On Jun 9, 10:51 pm, Phoenix Rising <[email protected]> wrote:
>
>       # File vendor/rails/activerecord/lib/active_record/base.rb, line
> 2619
> 2619:       def update_attributes(attributes)
> 2620:         self.attributes = attributes
> 2621:         save
> 2622:       end
>
> What I don't "get" is how self.attributes = attributes works.

The attributes= method is badly named, since it's not actually an
assignment. A better name would be merge_attributes. The
implementation is basically

new_attributes.each do |key, value|
  send(key + '=', value)
end

Fred
> Obviously it's assigning based on the passed-in parameters hash, but
> given in my example that hash did NOT contain "condition" or "value",
> it seems to skip those and go with whatever the current values are.
> And as far as I know, this has been standard with update_attributes
> from day one.
>
> So - and somebody please verify or correct my understanding - as long
> as the hash I pass in to update_attributes doesn't overwrite my prior
> manual assignment methods, this functionality should continue -
> through future updates to the framework - to work as expected -
> correct?
>
> And if the above is correct, does anybody see anything else wrong that
> I may not have considered with doing things this way?
>
> Thanks again =)
>
> On Jun 9, 3:05 pm, Perry Smith <[email protected]>
> wrote:
>
> > I don't see the "multiple" calls to save.
>
> > update_attributes will call save but I don't see the other call to save.
>
> > By the way, update_attributes calls save (as of 2.3.2? or was it before
> > that) only if at least one attribute has changed.
> > --
> > Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" 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-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to