我们可以重命名资源集合/成员URL吗?

时间:2015-06-01 16:46:52

标签: ruby-on-rails ruby-on-rails-3

我在routes.rb中有这个资源

resources :orders, only:[] do
    collection do 
      post :user_order_confirmation
    end  
 end

在HTML视图'orders / carrier_order_confirmation'中创建这样的路径。我们可以做一些这条路径看起来像'orders / user_confirmation'吗?

3 个答案:

答案 0 :(得分:1)

你可以做到

resources :orders, only:[] do
    collection do 
      post :user_confirmation, acion: :user_order_confirmation
    end  
 end

这将为您提供所需的确切路线。这是测试:

$ rake routes | grep orders
user_confirmation_orders POST /orders/user_confirmation(.:format) orders#user_confirmation {:acion=>:user_order_confirmation}

答案 1 :(得分:0)

您可以在设置资源路由后在routes.rb中添加以下行来覆盖常规路由:

get "/orders/user_confirmation" => "orders#user_confirmation", as: "user_confirmation"

澄清一下,这是每个部分的含义:

[Routing Method] "/[Route You want]" => "[Controller]#[Controller Method]", as: "[Custom Route Name]"

答案 2 :(得分:0)

试试这个 post:user_order_confirmation,as :: user_confirmation