I have 2 models:
:households (belongs_to: user)
:users (has_many :households)
:user has an attribute, name.
when using active scaffold to list households, i'd like to show a
column that is household.user.name
i read the AS documentation and found that it recommends creating a
virtual attribute in household.rb, of the form:
def name
"#{self.user.name}"
end
so far so good...
now i want to be able to update household.user.name when updating a
household. so, i added a write accessor to household.rb:
def first_name=(name)
self.user.first_name = name
end
my updates were silently failing. then i realized that, not
surprisingly, AS is doing a household.save somewhere, but is not doing
a household.user.save. so, i added the save to my write accessor:
def first_name=(name)
self.user.first_name = name
self.user.save
end
this works, but leaves me feeling a little squeamish... is this the
recommended way to do this? does AS have a more direct mechanism for
updating model.associated_model.attribute that I am missing in my
reading? if i need to explicitly save associated records that might
be updated, should i do so in a central place (such as in
before_update_save)?
many thanks for any guidance.
yoram
update the household model, i'd like to also be able to update
household.user.name.
i'm not sure what the best way to do this is. i read the AS
documentation that seems to recommend creating
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/activescaffold?hl=en
-~----------~----~----~----~------~----~------~--~---