Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4 Strong parameters : permit all attributes?

I'm building a web app with Rails 4 strong parameters.

When building the admin back office controllers, I wonder what is the best way to permit all the model attributes?

For now, I wrote this:

def user_params    params.require(:user).permit(User.fields.keys) end 

Do you think of a better way?

like image 807
Nicolas Blanco Avatar asked Dec 25 '12 20:12

Nicolas Blanco


1 Answers

You can call the bang version of permit.

params.require(:user).permit! 

Strong Params README on Github

Source code for reference:

def permit!   each_pair do |key, value|     convert_hashes_to_parameters(key, value)     self[key].permit! if self[key].respond_to? :permit!   end    @permitted = true   self end 
like image 183
Damon Aw Avatar answered Oct 02 '22 14:10

Damon Aw