With Ruby 1.9.3, Rails 3.2.13, Strong_parameters 0.2.1:
I followed every sign in textbooks and railscasts, but I can't get strong_parameters to work. It should be something really simple, but I donβt see where the error is.
configurations / Initializers / strong_parameters.rb:
ActiveRecord::Base.send(:include, ActiveModel::ForbiddenAttributesProtection)
configurations / application.rb
config.active_record.whitelist_attributes = false
application / models / product.rb
class Product < ActiveRecord::Base end
application / 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 throws a Forbidden Attributes exception, as expected. But when I go to:
... def create @product = Product.new(product_params)
Then, if I go to the form and enter "Name: product 1" and "Color: red", an exception does not occur; the new product is stored in the database without color, but with the correct name.
What am I doing wrong?