我如何从我拥有的特定路线中找到路径助手

How can i find the path helper from specific route i have

我有一个特定的路径助手,它在 rails 2.3 中完美运行,但在 rails 3.1 中抛出错误。

这是路径助手。

shipping_price_store_return_path(store)

当我在 rails 3.1 中使用它时,它给我错误提示

NoMethodError: undefined method `shipping_price_store_return_path' for #<ActionDispatch::Integration::Session:0x007fb2da730228>

当我 运行 rake routes 这就是我得到的 shipping_price_store_return_index /stores/:store_id/return/shipping_price(.:format) {:action=>"shipping_price", :controller=>"return"}

谁能指出这里可能出了什么问题。

以下是路由文件的内容

resources :stores do      
      resources :return do
        match :shipping_price, :on => :collection
      end
end

由于您的资源名称是 :return 而不是 :returns,因此 Rails 决定将 _index 添加到嵌套在其下的任何集合中。此更改已从 rails 3 开始完成。

所以新的 rails 3 路线应该是:

shipping_price_store_return_index_path

如果你想避免 _index 那么你可以使用 resources :returns 或者你可以 resource :return.