Virtual attributes and mass assignment
lapitsky opened this issue · comments
I can define a virtual attribute in an ActiveRecord model class like
def virtual_attr
...
end
def virtual_attr=(val)
...
end
It allows me to make calls like model.update(virtual_attr: 'Hi!')
When I try to do the same for a decorated model class it fails in internal _assign_attribute
method. I think the reason is that it tries to do send(:virtual_attr=)
for the model object and does not find such a method there.
What is the recommended way to create virtual attributes in decorator classes so that I could do decorated_model.update(virtual_attr: 'Hi!')
?
Any news on this? I'm having this same problem.
Honestly... isn't this a bit out of scope? What prevents you from accessing the non decorated record directly?