2010-05-14 4 views
0

레일을 인스턴스화해야하는 고립 된 클래스에서 사용할 수 url_for :레일 :

    class ProfilePresenter < ActionController::Base 

attr_reader :profile 


def initialize(profile) 
    super 


    @a = url_for(:controller => 'profiles', :action => 'view', :profile_url => 'dd') 
    @a 

    @profile = profile 
     end 
    end 

가 어떻게 url_for 작업을 할 : url_for가 인스턴스화되어야하는 절연 클래스에서 사용할 수? 내가는 ActionController :: 자료와 ActionView :: Base를 확장하기 위해 노력하고 내가 캔트 :의 당신이 포함한다고 생각

+0

이 클래스는 어떻게 인스턴스화됩니까? 이것이 정상적인 컨트롤러 흐름의 일부가 아닌 경우 수동으로 요청 컨텍스트를 작성해야합니다. –

+0

모델에는 다음과 같은 방법이 있습니다. ProfilePresenter.new (self) –

답변

0

는 다음과 같은 시도 "ActionController :: UrlWriter 포함"

class ProfilePresenter < ActionController::Base 
    include ActionController::UrlWriter 
    attr_reader :profile 


    def initialize(profile) 
    super 
    @a = url_for(:controller => 'profiles', :action => 'view', :profile_url => 'dd') 
    @a 
    @profile = profile 
    end 
end 
+0

지금이 링크가 있습니다. 링크 할 호스트가 없습니다! 호스트 매개 변수를 제공하거나 default_url_options [: host]를 설정하십시오. 항상 호스트를 설정할 필요가없는 방법을 선호합니다. –