Strong params in Rails 4 (ArgumentError) -


situation

i want create new category using form.

in new.html.erb good:

<%= form_for @cat |f| %> <%= f.label :description %> <%= f.text_field :description %> <br> <%= f.label :position %> <%= f.text_field :position %> <%= f.submit %> <% end %> 

but after "submit" pressed argumenterror in categoriescontroller#create raised (unknown key: description). http://prntscr.com/1fijdk

categories_controller.rb

class categoriescontroller < applicationcontroller   def index     @categories = category.all   end    def new     @cat = category.new   end    def create     @category = category.find(params[:category])     redirect_to :categories   end end 

category.rb

class category < activerecord::base     has_many :items end 

schema.rb

activerecord::schema.define(version: 20130715035836)    create_table "categories", force: true |t|     t.string   "description"     t.integer  "position"     t.datetime "created_at"     t.datetime "updated_at"   end    create_table "items", force: true |t|     t.string   "name"     t.float    "price"     t.text     "description"     t.integer  "category_id"     t.datetime "created_at"     t.datetime "updated_at"   end  end 

in rails 3 works great, in rails 4 attr_accessible not generated , i'm little bit confused. problem?

rails 4 not use attr_accessible strong_parameters allow (or not) mass assignment. handled controller , not model, have specify in controller permitted attributes...

see : http://guides.rubyonrails.org/action_controller_overview.html#strong-parameters understand how works , @ https://github.com/rails/strong_parameters

cheers


Comments