Sunday, November 27, 2016

Overriding the devise default routes

I need to integrate devise gem in Rails5.0 application. It works flawless but the client requirements were he wants the urls  in very user friendly way like sign-in for users/sessions/new and more.

I override the routes in my routes.rb file to meet client requirements but as a result of it there were a lot of routes also there in the application which comes from the devise which we don't want. i made some changes and my routes.rb looks like

devise_for :users, :controllers => {registrations: 'registrations'}, 
:skip => [:sessions, :passwords, :registrations, :confirmations]
 

devise_scope :user do
  get 'sign-up' => 'devise/registrations#new', :as => :new_registration
  post "/sign-up" => "registrations#create"
  get '/forgot-password' => "devise/passwords#new", :as => :new_user_password
  post '/forgot-password' => "devise/passwords#create"
  get '/reset-password' => "devise/passwords#edit", as: :edit_user_password
  post '/reset-password' => "devise/passwords#create", as: :user_password
  put '/reset-password' => 'devise/passwords#update', as: :user_password_update
 
  post '/confirmation' => "devise/confirmations#create", :as => :user_confirmation
  get '/resend-confirmation' => "devise/confirmations#new", :as => :new_user_confirmation
  get '/confirmation' => "devise/confirmations#show", :as => :user_confirmation_show
  get '/my-profile' => "devise/registrations#edit", :as => :my_profile_edit
 
  get 'sign-in' => 'devise/sessions#new', :as => :new_user_session
  post 'sign-in' => 'devise/sessions#create', :as => :user_session
  delete 'sign-out' => 'devise/sessions#destroy', :as => :destroy_user_session
end

No comments: