Rails Generate Devise::session controller

Hi Folks,

Am new to rails.

I user devise in my project ,i need to write some conditions in my session controller.How can i generate devise session controller.

Devise::SessionsController

Please advice…

Hi Folks,

Am new to rails.

I used devise in my project ,i need to write some conditions in my session controller.How can i generate devise session controller.

Devise::SessionsController

Please advice…

  1. Create your custom controller, for example a Admins::SessionsController:
class Users::SessionsController < Devise::SessionsController
end
  1. Tell the router to use this controller:
devise_for :users, :controllers => { :sessions => "users/sessions" }
  1. we changed the controller, it won’t use the “devise/sessions” views, so remember to copy “devise/sessions” to “user/sessions”.

Any queries follow the topic

Configuring controllers

in the page

https://github.com/plataformatec/devise

Hi,

I created session::controller as u said and also used routes like devise_for :users, :controllers => { :sessions => “users/sessions” }

But i got an error

Routing Error

uninitialized constant Users

Try running rake routes for more information on available routes.

Please advice…

Because you don't have a User model.

I have user.rb model.

Your error saying that you don't have Users model and controler may be you created the devise as Admin. If so please replace user with admin in all places.

If u want to understand flow take new project and try documentation (GitHub - heartcombo/devise: Flexible authentication solution for Rails with Warden. ) from top to bottom, then u will understand flow after that you can implement in your project .

I have also faced the same issue. I had 2FA integration for active admin and it was working fine for me. but I have to upgrade my ruby and rails version to ruby 3.2.1 and rails 7 When I updated this I faced the same issue it started giving rake aborted! NameError: uninitialized constant Devise::SessionsController (NameError)

class SessionsController < ::Devise::SessionsController

**Solution** 

`# app/controllers/admin/custom_sessions_controller.rb
    module Admin
      class CustomSessionsController < ActiveAdmin::Devise::SessionsController
        include ::ActiveAdmin::Devise::Controller

        def create
          super do |resource|
            # Generate and save OTP
            resource.generate_and_save_otp
            puts "Mobile Verification code for admin login is #{resource.mobile_otp}"
            if resource.mobile_otp.present?
              redirect_to admin_otp_verification_path(resource_id: resource.id) and return
            end
          end
        end
      end
    end

`

routes.rb file custom_config = ActiveAdmin::Devise.config.merge( controllers: { sessions: ‘admin/custom_sessions’ } )

devise_for :admin_users, custom_config

ActiveAdmin.routes(self)