简体   繁体   中英

Devise : overriding the devise routes and controllers at the same time

i want to ovverride my devise routes and the sessions controller from this gem at the same time. How do i do this ?

I thought about :

 devise_for :admins, :skip => [:sessions], 
  controllers: { sessions: "admins/sessions" }

  devise_scope :admin do
    get    'login' => 'devise/sessions#new', :as => :new_admin_session
    post   'login' => 'devise/sessions#create', :as => :admin_session
    delete 'logout' => 'devise/sessions#destroy', :as => :destroy_admin_session
  end

but my paths are chaging but the controller - not. How can I implement this right ?

What about something like:

devise_for :admin, exclude: [:sessions] do
   get '/login', to: 'sessions#new', as: :new_admin_session
   post '/login', to: 'sessions#create', as: :admin_session
   delete '/logout', to: 'sessions#destroy', as: :destroy_admin_session
end

When you specify controllers: { sessions: "admins/sessions" } , that implies that you have a file called sessions_controller.rb in this path: app/controllers/admins/sessions_controller.rb , and that it starts with:

module Admins
  class SessionsController < Devise::SessionsController

If this is the controller you want your app to use, then in the devise_scope block, you must tell it to use admins/sessions , not devise/sessions , like this:

devise_scope :admin do
  get    'login' => 'admins/sessions#new', :as => :new_admin_session
  post   'login' => 'admins/sessions#create', :as => :admin_session
  delete 'logout' => 'admins/sessions#destroy', :as => :destroy_admin_session
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM