rails/rails — Issue #4583: Can't set custom non-db attributes using ActiveRecord::Base#[]=
Author: mptre
Created: 2012-01-21 20:00:28+00:00
State: open

This is probably not classified as an issue but I did notice a change in behavior after upgrading a Rails app from 3.1 to the newly released 3.2 version.

After running my test suite lots of errors occurred while trying to set a custom non-db attribute value using the `ActiveRecord::Base#[]=` method. See example below:

``` ruby

class User < ActiveRecord::Base
# custom non-db attribute
attr_accessor :activated

before_save -> { self[:activated] = true if token? && !activated_at? }

def activated?
!activated.nil?
end
end
```

The before_save lamba will throw the follwing exception:

```ActiveModel::MissingAttributeError: can't write unknown attribute `activated'```

Was this change of behavior intended with the 3.2 release?

Any clarity into this matter would be much appreciated!