我有一个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方法