如何鏈接到沒有路線幫手的動作?如何鏈接到沒有路線幫手的動作
我有一個路線
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'在我給的例子中工作? –