开发者

build_* not working despite being has_one

开发者 https://www.devze.com 2022-12-21 18:49 出处:网络
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_*

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

精彩评论

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