나는 다음과 같이 원하는 :모델 개체의 연결된 개체를 업데이트하려면 어떻게해야합니까?
@user.update_attributes(:name => "Obama", :profile => { :current_location => 'US' })
경우 사용자 has_one 프로필을.
나는 다음과 같이 원하는 :모델 개체의 연결된 개체를 업데이트하려면 어떻게해야합니까?
@user.update_attributes(:name => "Obama", :profile => { :current_location => 'US' })
경우 사용자 has_one 프로필을.
'중첩 된 속성'으로 지정하십시오. The documentation는 말한다 :
class Member < ActiveRecord::Base
has_one :avatar
accepts_nested_attributes_for :avatar
end
...
당신이 회원을 통해 아바타를 업데이트 할 수 있습니다 : bjelli가이 있기 때문에params = { :member' => { :avatar_attributes => { :id => '2', :icon => 'sad' } } }
member.update_attributes params['member']
member.avatar.icon # => 'sad'
한 아바타가있는 회원 모델을 고려 여기에 원하는 accepts_nested_attributes_for
방법이 나와 있습니다. 프로필의 : id 속성을 전달하는 것이 중요하다는 것을 알아 두는 것이 중요합니다.이 속성은 사용자가 원하는 업데이트임을 인식 할 수있게합니다.
자세한 내용을 보려면 nested_attributes.rb 개의 댓글을 읽는 것이 좋습니다.