【发布时间】:2013-07-25 07:05:30
【问题描述】:
这是一个奇怪的问题。
在我的应用程序助手中,有一个名为 test 的方法,还有一个名为 article_url 的方法。我有文章资源,并生成它的 url_helpers。在测试方法中,我调用了 article_url,但它访问的是 url_helper 方法,而不是我在 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
【问题讨论】:
-
向我们展示
code和error message -
这是一个疯狂的猜测。请尝试将代码“include ApplicationHelper”添加到ApplicationController中,然后进行测试。
标签: ruby-on-rails ruby-on-rails-3.2 helper helpermethods