2013-07-25 68 views
0

這是一個奇怪的問題。無法訪問幫助器方法?

在我的應用助手,有一個名爲測試方法,並命名爲article_url的另一種方法。我有文章資源,並生成它的url_helpers。在測試方法中,我打電話article_url,但它訪問url_helper方法,而不是我在助手中定義的方法。

我的項目在Rails 3.0中運行良好,但是當我升級到3.2時,它引發了這個問題。 3.2以下,開發模式運行良好但生產提出問題。

請原諒我的英語不好:-)

對不起,這樣的代碼:

# application_helper.rb 
module ApplicationHelper 

    ... 

    def article_url(article, html_suffix = true) 
    if article.redirect_to.present? 
     article.redirect_to 
    else 
     url = "#{Settings.host}/articles/#{article.created_at.strftime("%Y-%m-%d")}/#{article.id}" 
     url += ".html" if html_suffix 
     url 
    end 
    end 

    ... 

    def render_article_list(article) 
    link_to(xxx, article_url(article), {:target => "_blank"}) 
    end 

end 
+0

向我們展示'code'和'error message' –

+0

這是一個瘋狂的猜測。請嘗試將代碼「include ApplicationHelper」添加到ApplicationController中,然後對其進行測試。 –

+0

謝謝,代碼補充。 – winterwhisper

回答

0

重命名你的helper方法。如果您有名爲article_url的幫助程序和名爲article的資源,則article_url在路線和幫助程序之間將不明確。如果您不認爲這是問題,請發佈一些代碼以幫助我們縮小問題的範圍。