我有一个invoices_controller
资源路线。如下:
resources :invoices do
resources :items, only: [:create, :destroy, :update]
end
现在我想向发票添加发送功能,如何添加自定义路由invoices/:id/send
来发送请求,invoices#send_invoice
以及我应该如何在视图中链接到它。
传统的rails方法是什么。谢谢。
我有一个invoices_controller
资源路线。如下:
resources :invoices do
resources :items, only: [:create, :destroy, :update]
end
现在我想向发票添加发送功能,如何添加自定义路由invoices/:id/send
来发送请求,invoices#send_invoice
以及我应该如何在视图中链接到它。
传统的rails方法是什么。谢谢。
在您的路线中添加:
resources :invoices do
post :send, on: :member
end
或者
resources :invoices do
member do
post :send
end
end
那么在你看来:
<%= button_to "Send Invoice", send_invoice_path(@invoice) %>
或者
<%= link_to "Send Invoice", send_invoice_path(@invoice), method: :post %>
当然,您不受 POST 方法的束缚
resources :invoices do
resources :items, only: [:create, :destroy, :update]
get 'send', on: :member
end
<%= link_to 'Send', send_invoice_path(@invoice) %>
它将转到send
您的invoices_controller
.
match '/invoices/:id/send' => 'invoices#send_invoice', :as => :some_name
添加链接
<%= button_to "Send Invoice", some_name_path(@invoice) %>
在 Rails >= 4 中,您可以通过以下方式完成:
match 'gallery_:id' => 'gallery#show', :via => [:get], :as => 'gallery_show'
资源:发票确实得到“发送”,在::会员端