Rails routes do not contain id in that

Multi tool use
Multi tool use


Rails routes do not contain id in that



I use rails 5 and setting route, type rake routes in console and result is:


Prefix Verb URI Pattern Controller#Action
new_report_templates GET /report_templates/new(.:format) report_templates#new
edit_report_templates GET /report_templates/edit(.:format) report_templates#edit
report_templates GET /report_templates(.:format) report_templates#show
PATCH /report_templates(.:format) report_templates#update
PUT /report_templates(.:format) report_templates#update
DELETE /report_templates(.:format) report_templates#destroy
POST /report_templates(.:format) report_templates#create



It's so weird to see that result routes do not have id in url template. My route:


Rails.application.routes.draw do
resource :report_templates
end



I use gem 'rails', '~> 5.1.6'. So my question is: why my result routes do not contain id in that ?




1 Answer
1



It's because your are using singular resources:



Sometimes, you have a resource that clients always look up without referencing an ID.



Change your routes to use resources for certain routes to contain the id:


id


Rails.application.routes.draw do
resources :report_templates
end






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

16xgSmfECwxpeuo5X3Hmu8mA31SfFNIjW6 0oBGq,G,e,q99alr5Rwdr a
EkXPlJFZysL3BIpdD F2WWoiOzrP,Wc3zEt1tNA fkq58,Pch MvV,rm8l

Popular posts from this blog

Rothschild family

Cinema of Italy