[Ruby] How to configure routing with [rails]resources

less than 1 minute read

Set routing with #resources The routing can also be set individually. However, since the seven basic actions in rails are often used during development, Setting each time is not efficient. In such a case, if you use the resources method, you can set the routing automatically by writing one line.

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

Check with the rails routes command.

$ rails routes

Make sure all urls are set.

$ rails routes
                   Prefix Verb URI Pattern Controller#Action
                    blogs GET /blogs(.:format) blogs#index
                          POST /blogs(.:format) blogs#create
                 new_blog GET /blogs/new(.:format) blogs#new
                edit_blog GET /blogs/:id/edit(.:format) blogs#edit
                     blog GET /blogs/:id(.:format) blogs#show
                          PATCH /blogs/:id(.:format) blogs#update
                          PUT /blogs/:id(.:format) blogs#update
                          DELETE /blogs/:id(.:format) blogs#destroy
       rails_service_blob GET /rails/active_storage/blobs/:signed_id/*filename(.:format) active_storage/blobs#show
rails_blob_representation GET /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations#show
       rails_disk_service GET /rails/active_storage/disk/:encoded_key/*filename(.:format) active_storage/disk#show
update_rails_disk_service PUT /rails/active_storage/disk/:encoded_token(.:format) active_storage/disk#update
     rails_direct_uploads POST /rails/active_storage/direct_uploads(.:format) active_storage/direct_uploads#create