4

I'm very carefully following the RailsGuide and it's working beautifully, until Step 11. Adding Tags via a MultiModel form. Once I've added the code I get this error:

ActiveModel::MassAssignmentSecurity::Error in PostsController#update Can't mass-assign protected attributes: tags_attributes

Application Trace: app/controllers/posts_controller.rb:65:in block in update' app/controllers/posts_controller.rb:64:inupdate'

I've backed up and started over a few times to be certain it's not user error. Can someone help me get past this step. I'm so close to done ! Then I can move on to Hartl's tutorial. Thank you.

Will
  • 337
  • 4
  • 15

1 Answers1

2

This is not your fault!

The deployed Getting Started guide hasn't been updated for the Rails 3.2.3 default of

# in config/application.rb:

config.active_record.whitelist_attributes = true

The fix is to add this to your Post model:

# in app/models/post.rb

class Post < ActiveRecord::Base
  attr_accessible :tags_attributes
  ...

Incidentally, this whole section was removed from the source of the guide going forward, which you can find at https://github.com/rails/rails/blob/master/guides/source/getting_started.textile .

Gabe Kopley
  • 16,281
  • 5
  • 47
  • 60
  • 1
    The stable version of the guide available in http://guides.rubyonrails.org/getting_started.html is the version available in the 3-2-stable branch in the rails repo. The guide in the master branch is currently being rewritten to be more beginner friendly and is available in http://edgeguides.rubyonrails.org/getting_started.html. It's a work in progress and not 100% usable by beginners at this point in time. – Vijay Dev May 16 '12 at 06:59
  • 1
    Ahhhh ... I suspected as much. Also, that explains the mysterious extra line in my post.rb file that has attr_accessible for :content, :name, :title which I did not type in. Perhaps one of the generate or migrate steps in the guide added it ? Thank you much. I hope this will help other guide users. – Will May 16 '12 at 17:30
  • I have 'config.active_record.whitelist_attributes = true' in my application.rb and my pluralmodalname_attributes in my attr_accessible. However I still have that problem :/ ? – CanCeylan Jan 10 '13 at 09:03