Thanks, that worked.
The reason I'm updating attributes in this "complicated" way is that
I've overridden the credentials= assign method, so that I can handle
CUD (create, update, delete) operations on the association from the
same form w/o special-casing in the controller. The controller just
calls
@user.attributes = params[:user]
@user.save!
rescue
...
Thanks,
Wolf
On Jul 19, 11:08 pm, "Jack Danger Canty" <[EMAIL PROTECTED]>
wrote:
> On Sat, Jul 19, 2008 at 8:32 PM, Wolfram <[EMAIL PROTECTED]> wrote:
>
> > class User < ActiveRecord::Base
>
> > has_many :credentials do
> > def update(key,val)
> > cr = proxy_target.select{ |c| c.id == key.to_i}.first
> > cr.update_attributes(val) unless cr.nil?
> > end
> > end
>
> You don't need to call proxy_target yourself. The association proxy is
> built to allow you to treat it like it was the target. So the following
> should load the target and do what you want:
>
> def update(key,val)
> cr = detect { |c| c.id == key.to_i}
> cr.update_attributes(val) unless cr.nil?
> end
>
> Although you could probably find an easier way to update a record in the
> association.
>
> ::Jack Danger
>
> > Thanks,
>
> > Wolf
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" 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/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---