rails/rails — Issue #5129: Unknown Attributes on Models
Author: chadwtaylor
Created: 2012-02-22 15:57:07+00:00
State: open

This is not a bug issue but an enhancement request. I often come across with dealing with attributes that are not defined by a model thus raises `ActiveRecord::UnknownAttributeError`.

I implemented a mixin to trim the unknown attributes out and would be nice if such method can be incorporated. I'm pretty sure my mixin code isn't refactored well but feel free to make it better for any situations.

Here goes...

```ruby
module ActiveRecord
class Base

def self.trim_unknown_attributes(attrs)
temp = Hashie::Mash.new
[*self.new.attributes].each do |k,v|
attrs.each { |kk,vv| temp[k] = vv if k == kk }
end
return temp
end

end
end
```