Will
Will

Reputation: 347

Rails Guides - Step 11 - Multi Model Form - MassAssignmentSecurity error

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.

Upvotes: 4

Views: 426

Answers (1)

Gabe Kopley
Gabe Kopley

Reputation: 16667

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 .

Upvotes: 2

Related Questions