Rails - 匹配到命名空间控制器的路由

时间:2012-11-28 21:22:24

标签: ruby-on-rails

match '/submit_expense/:id' => 'expenses#submit_expense', :as => 'submit_expense'

我如何将此指向我的:admin命名空间?我是否必须在命名空间声明中定义匹配?

3 个答案:

答案 0 :(得分:20)

您可以在使用控制器生成器时使用/喜欢:

match '/submit_expense/:id' => 'admin/expenses#submit_expense', :as => 'submit_expense'

答案 1 :(得分:10)

routes.rb这可能会有用......

namespace :admin do
  match '/submit_expense/:id' => 'expenses#submit_expense', :as => 'submit_expense'
end

答案 2 :(得分:0)

您也可以像这样使用 to: 指令:

  get '/submit_expense/:id', to: 'admin/expenses#submit_expense'