Can't mass-assign protected attributes in Rails 4 -


i can't understand what's wrong code (rails 4):

parameters post:

{:name => "name"} 

new action:

m=menu.new(params.permit(:name)) 

last line of code generates "can't mass-assign protected attributes menu: name"

the standard way use strong_parameters in rails 4 create private method in controller defines permitted params. so:

def new   @m = menu.new(menu_params) end  private  def menu_params   params.require(:menu).permit(:name, :etc, :etc) end 

then, can remove attr_accessible line model.

see:

http://edgeapi.rubyonrails.org/classes/actioncontroller/strongparameters.html http://railscasts.com/episodes/371-strong-parameters


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -