1

假设我有一个名为发票的对象。在routes.rb我有

resources :invoices do
  get "pay"
end

当我跑步rake routes时,路线生成为

invoice_pay GET    /invoices/:invoice_id/pay(.:format) invoices#pay

并且参数是:invoices_id而不是:id

如果我使用匹配语句:

match "invoices/:id/pay" => "invoices#pay", :via => :get

我得到:

  GET    /invoices/:id/pay(.:format)         invoices#pay

在我看来,路线应该是pay_invoice_path(@invoice),但是,我还没有找到合适的文档。有什么建议么?

4

1 回答 1

1

我想你想做的是

resources :invoices do
  get "pay", :on => :member
end

看看指南: http: //guides.rubyonrails.org/routing.html

于 2013-02-17T18:12:25.060 回答