How to add custom routes to resource route
In Rails >= 4, you can accomplish that with:
match 'gallery_:id' => 'gallery#show', :via => [:get], :as => 'gallery_show'
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
resources :invoices do
resources :items, only: [:create, :destroy, :update]
get 'send', on: :member
end
<%= link_to 'Send', send_invoice_path(@invoice) %>
It will go to the send
action of your invoices_controller
.
match '/invoices/:id/send' => 'invoices#send_invoice', :as => :some_name
To add link
<%= button_to "Send Invoice", some_name_path(@invoice) %>