如何在Rails 3的功能测试中使用polymorphic_path [英] How to use polymorphic_path in a functional test in Rails 3

查看:131
本文介绍了如何在Rails 3的功能测试中使用polymorphic_path的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Rails 3的功能测试中使用polymorphic_path.

I'm trying to use polymorphic_path in a functional test in Rails 3.

起初我会得到

NoMethodError: undefined method `polymorphic_path' for #<ArticlesControllerTest:0x492f17c>

然后我添加了

include Rails.application.routes.url_helpers

undefined method error已停止,但现在常规路径(例如article_path(article))已停止工作:

The undefined method error stopped, but now regular paths, like article_path(article) for example stopped working:

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'

我曾经能够通过包含

include ActionController::UrlWriter

如何在Rails 3中使用它?

How can I get this to work in Rails 3?

推荐答案

我需要包括:

include ActionDispatch::Routing::UrlFor
include Rails.application.routes.url_helpers

并设置:

default_url_options[:host] = 'www.example.com'

我通过这篇博文发现了一个类似的问题 http://steve.dynedge.co. uk/2010/04/29/rails-3-rake-and-url_for/

I found out via this post that answers a similar issue http://steve.dynedge.co.uk/2010/04/29/rails-3-rake-and-url_for/

这篇关于如何在Rails 3的功能测试中使用polymorphic_path的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆