Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
  Willam Cougan
7,127 PointsCreating New Statuses in Treebook
As seen in the video "Creating Relationships" (Programming >Build a Simple Ruby on Rails Application >Customizing Forms >Creating Relationships), the error
"ActiveModel::MassAssignmentSecurity::Error in StatusesController#create
Can't mass-assign protected attributes: user_id"
is shown when creating a new status. When the problem is fixed in the video by adding ":user_id" to "status.rb", this doesn't work for me. After I save everything out, I still get that error. What can I do to fix this?
6 Answers
Willam Cougan
7,127 PointsAlso, I noticed that I get the error message: "Can't mass-assign protected attributes: user"
However, the video is: "Can't mass-assign protected attributes: user_id"
Not sure if that is a problem or not.
Zander Perry
2,227 PointsIn your Status model have you added :user_id to the attr_accessible list?
Also, have you set your belongs_to and has_many associations between your User and Status models?
Willam Cougan
7,127 PointsYes, I've done both of those. My code for the Status Model is:
attr_accessible :content, :user_id
belongs_to :user
and my code for the User Model is
has_many :statuses
  def full_name
   first_name + " " + last_name
  end
Daniel Beasley
4,824 PointsHey William do you have a :user_id within your status table? Check db/ migrate/schema.rb folder) it should look like below..
 create_table "statuses", :force => true do |t|
   t.text     "content"
   t.datetime "created_at", :null => false
   t.datetime "updated_at", :null => false
   t.integer  "user_id"
 end
  add_index "statuses", ["user_id"], :name => "index_statuses_on_user_id"
Willam Cougan
7,127 PointsDaniel, thanks for the input. I did not have that, but that still did not work for me. Also, was that in any of the videos?
Daniel Beasley
4,824 PointsHey William watch and follow this video.. This should fix your problem... You can't just added :user_id and save it you have to create and Database migration... The video should explain all this.. Let me know how it goes..
Daniel