Class User << ActiveRecord::Base has_one :profile delgate :description, :description=, :to => :profile end I''d like to do, @user = User.create(:name => ''Foo Bar'', :description => ''Slow.'') or @user = User.update_attributes(:description => ''Slow'') and have AR create/update the profile model and association (if it doesn''t already exist). How can I do this? Ideally this would be handled in User''s initialize, or callback, but I can''t get anything to work. When reaching the delegate statement I get an error that profile is nil. Thanks
Write Something like this in your user model before_create :build_profile_for_this_user def build_proile_for_this_user build_profile end On Nov 13, 7:34 am, twiggle <twigbra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Class User << ActiveRecord::Base > has_one :profile > delgate :description, :description=, :to => :profile > > end > > I''d like to do, > > @user = User.create(:name => ''Foo Bar'', :description => ''Slow.'') > or > @user = User.update_attributes(:description => ''Slow'') > > and have AR create/update the profile model and association (if it > doesn''t already exist). > > How can I do this? Ideally this would be handled in User''s > initialize, or callback, but I can''t get anything to work. When > reaching the delegate statement I get an error that profile is nil. > > Thanks
Seemingly Similar Threads
- A bit OT: LDAP and AD interoperability with LDAP as master
- `build_association` produces DB-queries
- Do delegates work properly in Drb mode?
- Help: delegated association 'App' returning ActionDispatch::Integration::Session instead
- Help: I need community delegates