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

Failed to invoke helpers with activejob #97

Open
Aaron2Ti opened this issue Nov 24, 2018 · 2 comments
Open

Failed to invoke helpers with activejob #97

Aaron2Ti opened this issue Nov 24, 2018 · 2 comments

Comments

@Aaron2Ti
Copy link

From the readme, it says:

ActiveDecorator::ViewContext.run_with ApplicationController.new.view_context do
  ## perform some heavy jobs here
end

However, what I did is the following

↪ rails runner 'ActiveDecorator::ViewContext.run_with(ApplicationController.new.view_context) { puts User.last.name_with_company }'
undefined method `name_with_company' for #<User:0x000000000b63ee70>
Did you mean?  name_will_change!

but maually extend would work:

↪ rails runner 'u = User.last; u.extend UserDecorator; puts u.name_with_company'
Foo Bar

Am i missing sth?

Regards

@Aaron2Ti
Copy link
Author

we've seen this on active_decorator (1.0.0)

@vala
Copy link
Contributor

vala commented Dec 4, 2018

Looking at the source code of the ActiveDecorator::ViewContext.run_with method, it seems to be made to allow the decorators to access a view context to use helpers, not to automatically decorate your models.

You still need to manually decorate your models, which I'll advise you to do with the following method : ActiveDecorator::Decorator.instance.decorate(u), as documented in the README, instead of manually extending your instance, since the #decorate method does more than just extending the model instance.

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

2 participants