I have an invoices_controller
which has resource routes. Like following:
resources :invoices do resources :items, only: [:create, :destroy, :update] end
Now I want to add a send functionality to the invoice, How do I add a custom route as invoices/:id/send
that dispatch the request to say invoices#send_invoice
and how should I link to it in the views.
What is the conventional rails way to do it. Thanks.
public function __construct(){ $this->middleware('auth'); } public function index(){ $envios = Envio::all(); return view('envios.
Resource routing allows you to quickly declare all of the common routes for a given resourceful controller. A single call to resources can declare all of the necessary routes for your index , show , new , edit , create , update , and destroy actions.
Custom routing allows you to display SEO-friendly URLs on your site that map behind-the-scenes to conventional Kibo eCommerce resources such as a product page or a search results page.
Add this in your routes:
resources :invoices do post :send, on: :member end
Or
resources :invoices do member do post :send end end
Then in your views:
<%= button_to "Send Invoice", send_invoice_path(@invoice) %>
Or
<%= link_to "Send Invoice", send_invoice_path(@invoice), method: :post %>
Of course, you are not tied to the POST method
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With