开发者

build_* not working despite being has_one

My intention here is just to create a correspo开发者_Go百科nding contact when a user signs up, but the said contact is never created, despite using build_* with a has_one:

Contact model:

has_one :user

User model:

belongs_to :contact

Users Controller:

def signup
  @user = User.new
end

def signup_success
 @user = User.find params[:id]
 contact = @user.build_contact
 contact.contactable = School.first
 contact.save
end

protected

routes:

map.resources :users,
:collection => {
  :signup => :get
},
:member => {
  :signup_success => :any
}

Any idea of what I'm doing wrong? Thanks for any suggestions.


Does it work if you pass the attributes to build?

contact = @user.build_contact(:contactable => School.first)  
contact.save
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜