I have made all attributes in a rails app not accessible using this application configuration option:
config.active_record.whitelist_attributes = true
In most cases I define a few attributes I want to be accessible as accessible using attr_accessible
in models. How do I make all attributes of a particular model accessible. Something like attr_accessible :all
.
You can make all attributes accessible by calling attr_protected
without arguments like that:
class User < ActiveRecord::Base
# roughly speaking sets list of model protected attributes to []
# making all attributes accessible while mass-assignment
attr_protected
end
I've found this approach more readable:
class User < ActiveRecord::Base
attr_accessible *column_names
end
Changing config.active_record.whitelist_attributes will affect all your models, whereas this will only apply to the one model.
The attr_protected way also works, but I find it confusing (since it's doing the opposite of what it seems to say at first glance).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With