Rails 4 Include Helper inside Service Object

2.5k views Asked by At

I am currently trying to use a Devise helper inside a service object

class ServiceObject
    include Devise::Controllers::Helpers

But I get

undefined method `helper_method' for ServiceObject:Class

Any idea how to use such a helper inside the service object?

2

There are 2 answers

0
Florian Eck On

The problem is that helper_method is a method defined by ActionController::Base. So including the module only works in subclasses of them.

If the helper is already included in your ApplicationController you could simply use ApplicationController.new.method_to_call

0
Rubyrider On

Try using presentar. Probably you can use decorator gem. So that you can keep your presentation layer seperate and can be easily used any level of framework stack.