amatsuda/active_decorator

Failed to invoke helpers with activejob

Aaron2Ti opened this issue · 2 comments

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

we've seen this on active_decorator (1.0.0)

vala commented

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.