Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Virtual attributes and mass assignment #840

Open
lapitsky opened this issue Jan 14, 2019 · 2 comments
Open

Virtual attributes and mass assignment #840

lapitsky opened this issue Jan 14, 2019 · 2 comments

Comments

@lapitsky
Copy link

lapitsky commented Jan 14, 2019

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!')?

@thaispeixoto
Copy link

Any news on this? I'm having this same problem.

@klyonrad
Copy link

Honestly... isn't this a bit out of scope? What prevents you from accessing the non decorated record directly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants