I sometimes need to update attributes in mass after initialization
without having to save the record (what #update_attributes does).
This doesn't seem to be possible in any nice way right now. For
example, @obj.attributes.merge!(:field => 'new text') doesn't stick.
I've been experimenting with this method and it seems to do the trick:
module ActiveRecord
class Base
def merge_attributes!(attributes = {})
attributes.each_pair do |att, value|
self.send("#{att}=", value) if self.respond_to?("#{att}=")
end
self.attributes
end
end
end
Anyone else find that useful? Or harmful? If it makes sense to others
ill patch it up.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---