2017-02-21 12 views
1

레일 엔진에 엔진을 탑재했습니다. 컨트롤러에서 나는 엔진 경로 도우미에 경로의 접두어 앞에 엔진 이름을 붙여서 액세스 할 수 있습니다. myengine.articles_path. 서비스 클래스에서이 헬퍼에 액세스하려고합니다. 일반적으로 나는 즉서비스 클래스의 레일 엔진 경로 도우미 사용

class SomeService 
    include Rails.application.routes.url_helpers 

end 

이, 예를 들어, 내 주요 응용 프로그램의 도우미에 액세스 할 날 수있는 url_helpers을 포함 할 것 root_path,하지만 난 myengine.articles_path을하려고하면 나는 서비스 클래스 또는 같은 일부 모듈에 엔진 경로 도우미에 액세스하려면 어떻게

undefined local variable or method `myengine' 

를 얻을?

답변

2

class << self

class SomeService 
    class << self 
    include Rails.application.routes.url_helpers 
    end 
end 
에 투입되어야한다