奇异路由服务参数:object_id而不是:id

时间:2013-02-17 11:36:17

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

说我有一个名为invoice的对象。在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),但是,我还没有找到合适的文件。有什么建议吗?

1 个答案:

答案 0 :(得分:1)

我认为你要做的是

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

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