ruby on rails - Strong_parameters not working -


with ruby 1.9.3, rails 3.2.13, strong_parameters 0.2.1:

i have followed every indication in tutorials , railscasts, can not strong_parameters working. should simple, can not see error.

config/initializers/strong_parameters.rb:

activerecord::base.send(:include, activemodel::forbiddenattributesprotection) 

config/application.rb

config.active_record.whitelist_attributes = false 

app/models/product.rb

class product < activerecord::base end 

app/controllers/products_controller.rb:

class expedientescontroller < applicationcontroller   ...   def create     @product = product.new(params[:product])     if @product.save       redirect_to @product     else       render :new     end   end end 

this raises forbidden attributes exception, expected. when move to:

 ...   def create     @product = product.new(product_params)     # , same flow before   end   private   def product_params     params.require(:product).permit(:name)   end 

then, if go form , enter "name: product 1" , "color: red" no exception raised; new product saved in database no color right name.

what doing wrong?

solved.

by default, use of not allowed attributes fails silently , submitted attributes filtered out , ignored. in development , test environments error logged well.

to change default behaviour, instance in development enviroment: config/environments/development.rb:

# raises error on unpermitted attributes assignment   config.action_controller.action_on_unpermitted_parameters = :raise  # default :log 

to honest, explained in github repository.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -