【发布时间】:2015-11-18 03:16:12
【问题描述】:
如何在没有路由助手的情况下链接到操作?
我有路线
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
我明白了
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 Routing from the Outside In”和“Getting Started with Rails”,但没有发现任何帮助。
我可以将路由更改为
get '/batches/:id/creation_wizard/add_funds' => 'batch::creation_wizard#add_funds', as: :creation_wizard_add_funds
并依赖于路由助手,但这感觉很老套。
我正在使用 Rails 3.2.22。
我做错了什么?
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 rails-routing