2
votes

I have mounted an engine in my rails app. In a controller, I can access the engine path helpers by prefixing the path with the name of the engine e.g. myengine.articles_path. I want to access these helpers in a service class. Normally I would include the url_helpers i.e.

class SomeService
  include Rails.application.routes.url_helpers

end

This allows me to access the helpers in my main app, e.g. root_path, but if I try myengine.articles_path I get

undefined local variable or method `myengine'

How do I access the engine path helpers in a service class or some module like that?

1

1 Answers

6
votes

It has to be put into class << self

class SomeService
  class << self
   include Rails.application.routes.url_helpers
  end
end