Published | 30/05/2021 |
---|---|
Last Updated | 18/11/2024 |
get 'photos/:id', to: 'photos#show', defaults: { format: 'jpg' }
defaults format: :json do
resources :photos
end
Create a new directory config/routes
Add a routes file into this directory, for example admin.rb
# config/routes/admin.rb
namespace :admin
roots 'users#index'
end
In the main routes file (config/routes.rb
) we could import the routes file above like follow:
# config/routes.rb
draw :admin
# List all routes
rails routes
rails routes --expanded # display in expanded table format
# Find routes by grep
rails routes -g new_comment
# is equivalent to
rails routes | grep new_comment
# Find routes by controller
rails routes -c users
rails routes -c admin/users
rails routes -c Comments
rails routes -c Articles::CommentsController