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