2010-05-14 47 views
0

Rails的可用:url_for可用在一個單獨的類必須被實例化:的Rails: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工作? 我試圖延長的ActionController ::基地和::的ActionView基地,我不能:■

+0

這個類如何被實例化?如果它不是正常控制器流程的一部分,則需要手動構建請求上下文。 – 2010-05-15 01:23:11

+0

在模型中有這樣的方法: ProfilePresenter.new(self) – 2010-05-15 11:05:21

回答

0

我認爲你必須包括 「包括的Act​​ionController :: 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 [:主機] 我喜歡的方式並不總是必須設置主機:s是可能的嗎? – 2010-05-15 11:04:35

相關問題