Let’s say you have a few routes that are all related, but don’t really map to the usual resources. For example, a login/logout controller named SessionsController doesn’t really fit the usual resourceful route model. One could use the usual routes HTTP verb syntax like this
Rails.application.routes.draw do #... get 'login', to: 'sessions#index' post 'login', to: 'sessions#login' post 'logout', to: 'sessions#logout' end
Rails.application.routes.draw do #... controller :sessions do get :login, action: :index post :login, action: :login post :logout, action: :logout end end
rake routes or
rails routes to see what routes we’ve got, we’ll see three routes.
login GET /login(.:format) sessions#index POST /login(.:format) sessions#login logout POST /logout(.:format) sessions#logout
If there’s an even better way, let me know in the comments!