Andrew Kaspick
2006-Oct-04 08:07 UTC
seeking feedback on "mass" protected attribute assignment
Hello,
I was wondering what people think about some improvements I''ve made
(local) regarding protected attribute assignment to the
ActiveRecord::Base attribute methods such as...
new (initialize)
create (in associations too)
build (in associations)
update_attributes
These methods accept a list of attributes to assign to an object and
removes any protected attributes defined in the model, which is fine.
I''ve found though that having to deal with assigning many protected
attributes to be a bit ugly as is...
If I have no protected attributes, I can do this...
SomeClass.create params[:some_class]
If I have one protected attribute, I can do this...
sc = SomeClass.new params[:some_class]
sc.update_attribute :prot_attrib, x
If I have many protected attributes, I can do this...
sc = SomeClass.new params[:some_class]
sc.prot_attrib1 = x
sc.prot_attrib2 = y
sc.save
My proposed solution would allow me to do this...
SomeClass.create params[:some_class], {:prot_attrib1 => x, :prot_attrib2
=> y}
So the methods I mentioned above would all accept a 2nd list of
attributes for protected assignment. This makes the code cleaner and
clearly seperates the two sets of attributes.
Does anybody see any issues with such an approach? There are some
minor things that I''ve had to deal with in my own implementation, but
as a whole, would this be worthwhile making into a plugin or
submitting as a patch? Or is there some reason I''m not aware or
thinking of that would make this a bad idea?
Thanks,
Andrew
--~--~---------~--~----~------------~-------~--~----~
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 rubyonrails-core@googlegroups.com
To unsubscribe from this group, send email to
rubyonrails-core-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core
-~----------~----~----~----~------~----~------~--~---