Skip to content

Instantly share code, notes, and snippets.

@rahul100885
Created May 6, 2014 05:01
Show Gist options
  • Save rahul100885/c5985bc8c49a9efc8fc6 to your computer and use it in GitHub Desktop.
Save rahul100885/c5985bc8c49a9efc8fc6 to your computer and use it in GitHub Desktop.
How to: override devise default routes of sign in and sign out
MyApp::Application.routes.draw do
# If you concern about SEO then send permanent redirect (301) on old routes to new routes
# It is always better to do this setting in web server that is in nginx or apache.
# Here I am showing how to do it in rails routes file
get '/users/sign_in', to: redirect("/sign-in")
get '/users/sign_up', to: redirect("/sign-up")
# Need to skip session and registration so that we can override them in devise_scope block
# If we not do so then default route of devise continue to work
devise_for :users, :skip => [:sessions, :registrations]
# Override all required routes which you uses. There are another routes
# which devise provide with session and registration which we skipped
# above.
# for session we have overridden all routes i.e new, create and destroy
# for registration we have overrides only new and create but
# registration has following default routes
# cancel_user_registration GET /users/cancel(.:format) registrations#cancel
# user_registration POST /users(.:format) registrations#create
# new_user_registration GET /users/sign_up(.:format) registrations#new
# edit_user_registration GET /users/edit(.:format) registrations#edit
# PATCH /users(.:format) registrations#update
# PUT /users(.:format) registrations#update
# DELETE /users(.:format) registrations#destroy
devise_scope :user do
get "sign-in", to: "devise/sessions#new", as: :new_user_session
post "sign-in", to: "devise/sessions#create", as: :user_session
delete "sign-out", to: "devise/sessions#destroy", as: :destroy_user_session
get "sign-up", to: "devise/registrations#new", as: :new_user_registration
post "sign-up", to: "devise/registrations#create", as: :user_registration
end
resources :posts
root 'posts#index'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment