如何链接到没有路线帮手的动作?如何链接到没有路线帮手的动作
我有一个路线
get '/batches/:id/creation_wizard/add_funds' => 'batch::creation_wizard#add_funds'
如果我在Rails的做控制台
include Rails.application.routes.url_helpers
default_url_options[:host] = "localhost"
url_for(controller: 'batch::creation_wizard', action: 'add_funds', id: 1)
我得到"http://localhost/batches/1/creation_wizard/add_funds"
但是,如果我有
class Batch::CreationWizardController < ApplicationController
def my_method
redirect_to controller: 'batch/creation_wizard', action: 'add_funds', id: 1
end
end
时I g等
No route matches {:controller=>"batch/batch::creation_wizard", :action=>"add_funds", :id=>1}
如果我尝试
redirect_to controller: 'creation_wizard', action: 'add_funds', id: 1
我得到
No route matches {:controller=>"batch/creation_wizard", :action=>"add_funds", :id=>1}
如果我尝试
redirect_to action: 'add_funds', id: 1
我得到
No route matches {:action=>"add_funds", :id=>1, :controller=>"batch/creation_wizard"}
我尝试阅读Rails指南“从外部输入的Rails路由”和“Rails入门”,但我没有注意到任何帮助。
我可以在路由改变
get '/batches/:id/creation_wizard/add_funds' => 'batch::creation_wizard#add_funds', as: :creation_wizard_add_funds
,并依靠在路线上的帮手,但那种感觉哈克。
我正在使用Rails 3.2.22。
我在做什么错?
为什么'redirect_to action:'add_funds',id:1'在我给的例子中工作? –