Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Can't mass-assign protected attributes: parent_id #101

Closed
rschmitty opened this Issue · 2 comments

2 participants

Rick Schmitty John Rees
Rick Schmitty

When trying to save an object I get the following error

Can't mass-assign protected attributes: parent_id

In the form I've used code from the wiki

<%= f.label :parent_id %><br />
<%= f.collection_select :parent_id, @pages, :id, :name_for_selects, :include_blank => true %>

And in my create method I have

@page = Page.new(params[:page])

The debut post shows my form values

{"utf8"=>"?",
 "authenticity_token"=>"zIjEudxjrRIMq+ZWkgeE6lmX7hZxY6lm1h0OKOyu3eU=",
 "page"=>{"title"=>"About",
 "parent_id"=>"1"},
 "commit"=>"Create Page"}

I've followed the readme to include has_ancestry in my Page model. It also fails with the same error from console

Page.create! :title => 'Test', :parent => Page.create!(:title=>'Test Parent')

What am I missing?

John Rees

Have you got attr_accessible :parent_id in your Page model?

Rick Schmitty

Ah for some reason I thought that would be bad. Yes it works with that in attr accessible

Rick Schmitty rschmitty closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.