4

polymorphic_pathRails 3 の機能テストで使用しようとしています。

最初は私が得るだろう

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

そして、私は追加しました

include Rails.application.routes.url_helpers

停止しました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で動作させるにはどうすればよいですか?

4

3 に答える 3

6

私は含める必要があります:

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/

于 2011-08-11T03:22:39.753 に答える
-1

やってみました:

Rails.application.routes.url_helpers.polymorphic_path

?:)

于 2011-08-10T09:42:57.260 に答える