मैं दो मॉडल हैं:
User
(ईमेल: स्ट्रिंग)
Profile
(नाम: स्ट्रिंग)
रेल प्रतिनिधि अद्यतन कॉल
class User < ActiveRecord::Base
has_one :profile
delegate :name, :name=, :to => :profile
end
class Profile < ActiveRecord::Base
belongs_to :user
end
rails c
u = User.new
u.build_profile #=> init Profile
u.name = 'foo'
u.email = '[email protected]'
u.save #=> both User and Profile are saved
u.name = 'bar'
u.save #=> true, but changes in Profile were not saved!
u.email = '[email protected]'
u.save #=> true, new User email was saved, Profile - still not!
u.name #=> 'bar', but in database it's 'foo'
क्यों प्रोफ़ाइल अद्यतन नहीं किया जा रहा है (केवल पहली बार सहेजा गया)? इसे कैसे ठीक करें?