我正在尝试使用polymorphic_path
在 Rails 3 的功能测试中。
一开始我会得到
NoMethodError: undefined method `polymorphic_path' for #<ArticlesControllerTest:0x492f17c>
然后我添加了
include Rails.application.routes.url_helpers
The undefined method error
停止了,但现在是常规路径,例如article_path(article)
例如停止工作:
NameError: undefined local variable or method `default_url_options' for #<ArticlesControllerTest:0x33ccbe0>
.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.9/lib/action_dispatch/testing/assertions/routing.rb:175:in `method_missing'
.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.9/lib/action_dispatch/routing/url_for.rb:102:in `url_options'
.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.9/lib/action_dispatch/routing/url_for.rb:131:in `url_for'
.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.9/lib/action_dispatch/routing/route_set.rb:195:in `article_path'
我曾经能够通过包含在Rails 2中正常使用polymorphic_path
include ActionController::UrlWriter
我怎样才能让它在 Rails 3 中工作?
我需要包括:
include ActionDispatch::Routing::UrlFor
include Rails.application.routes.url_helpers
and set:
default_url_options[:host] = 'www.example.com'
我通过这篇文章发现回答了类似的问题http://steve.dynedge.co.uk/2010/04/29/rails-3-rake-and-url_for/ http://steve.dynedge.co.uk/2010/04/29/rails-3-rake-and-url_for/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)