Rails路线,意外结果(需要发布路线,而不是获得路线)

时间:2019-06-25 18:19:35

标签: ruby-on-rails ruby-on-rails-5

我有两条路。

checkout GET    /checkout/:product_id(.:format)   checkout#new                                           
         POST   /checkout(.:format)               checkout#create                                                       

我希望在发布命令中使用checkout_path,但是由于某种原因,如果我使用checkout_path(),它将始终返回获取路径。

/checkout/some_id
vs
/checkout


  get  "welcome"                               => "checkout#show"
  get  "checkout/:product_id"                  => "checkout#new", :as => :checkout
  post "checkout"                              => "checkout#create"

1 个答案:

答案 0 :(得分:0)

checkout_path助手来自您的:as => :checkout,所以:

  get  "welcome"              => "checkout#show"
  get  "checkout/:product_id" => "checkout#new",    as: :some_other_name
  post "checkout"             => "checkout#create", as: :checkout