Rod McLaughlin


No more attr_accessible in Ruby on Rails 4 (01 feb 13)

In a file called list.rb, I had

  attr_accessible :title, :user_id, :updated_at, :created_at   

When you run the tests using 'edge' Rails (4.0.0 beta), you get an error like this: "`attr_accessible` is extracted out of Rails into a gem. Please use new recommended protection model for params(strong_parameters) or add `protected_attributes` to your Gemfile to use old one."

What does this mean? This blog tells you:

http://logicalfriday.com/2012/10/15/sneaking-a-peak-at-rails-4/

Remove the attr_accessible line from your models. In each of the controllers, add at the bottom something like this (for example, this is list_controller):

 private
  def app_params
    params.require(:list).permit(:title, :user_id, :updated_at, :created_at)
  end

and, where you create a new list in the controller (the create method), instead of

@list = List.create(params[:list])

 

you should have


@list = List.create( app_params )

 

(Edge Rails commit b0d4a205713154a4cd3c065e8bdb42431f63dd74, 1/31/13 16:40:07 -0800)

 



Back
Portland London