rails/rails — Issue #4051: Mass assigment error when building associated object [3.2.0.rc1]
Author: morgoth
Created: 2011-12-20 11:36:27+00:00
State: open

Mass assigment doesn't allow to build associated objects when association_id is protected.
This was working fine in rails 3.1

Short example:

```ruby
class Post < ActiveRecord::Base
has_many :comments
end

class Comment < ActiveRecord::Base
belongs_to :post

attr_accessible :content
end
```

When running:

```ruby
post = Post.create(title: "Debugging")
post.comments.build
```

Error is thrown:
`ActiveModel::MassAssignmentSecurity::Error: Can't mass-assign protected attributes: post_id`

Sample application to reproduce bug:
https://github.com/morgoth/mass-assigment-bug

I tried to write failing test case, but this test is passing (which shouln't I suppose)
https://github.com/morgoth/rails/commit/8bde0d2f2b9ba2f878b4c2b630b692a5999c464e