升级后未初始化的常量 Devise::SessionsController

问题描述 投票:0回答:2

我有一个基于

rails 5.2
ruby 2.7.1, devise 4.7.2
构建的
activeadmin 2.9.0
应用程序。我想将其更新到当前版本。当我将
ruby
更新为
3.2.1
rails
更新为
7.0
devise
更新为
4.9.2
activeadmin
更新为
2.13
时,我得到了

uninitialized constant Devise::SessionsController in gem lib file .rvm/gems/ruby-3.2.1/gems/activeadmin-2.13.1/lib/active_admin/devise.rb:54:in <module:Devise>':

uninitialized constant Devise::SessionsController (NameError)
from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/activeadmin-2.13.1/lib/active_admin/devise.rb:7:in `<module:ActiveAdmin>'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/activeadmin-2.13.1/lib/active_admin/devise.rb:6:in `<main>'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/zeitwerk-2.6.4/lib/zeitwerk/kernel.rb:38:in `require'
    from /home/ahmad/Project/cuddleClone/oms-version-update/config/initializers/active_admin.rb:350:in `<main>'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/railties-7.0.4.3/lib/rails/engine.rb:667:in `load'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/railties-7.0.4.3/lib/rails/engine.rb:667:in `block in load_config_initializer'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/activesupport-7.0.4.3/lib/active_support/notifications.rb:208:in `instrument'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/railties-7.0.4.3/lib/rails/engine.rb:666:in `load_config_initializer'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/railties-7.0.4.3/lib/rails/engine.rb:620:in `block (2 levels) in <class:Engine>'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/railties-7.0.4.3/lib/rails/engine.rb:619:in `each'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/railties-7.0.4.3/lib/rails/engine.rb:619:in `block in <class:Engine>'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/railties-7.0.4.3/lib/rails/initializable.rb:32:in `instance_exec'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/railties-7.0.4.3/lib/rails/initializable.rb:32:in `run'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/railties-7.0.4.3/lib/rails/initializable.rb:61:in `block in run_initializers'
    from /home/ahmad/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/tsort.rb:228:in `block in tsort_each'
    from /home/ahmad/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
    from /home/ahmad/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
    from /home/ahmad/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/tsort.rb:431:in `each_strongly_connected_component_from'
    from /home/ahmad/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/tsort.rb:421:in `block in each_strongly_connected_component_from'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/railties-7.0.4.3/lib/rails/initializable.rb:50:in `each'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/railties-7.0.4.3/lib/rails/initializable.rb:50:in `tsort_each_child'
    from /home/ahmad/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/tsort.rb:415:in `call'
    from /home/ahmad/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/tsort.rb:415:in `each_strongly_connected_component_from'
    from /home/ahmad/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/tsort.rb:349:in `block in each_strongly_connected_component'
    from /home/ahmad/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/tsort.rb:347:in `each'
    from /home/ahmad/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/tsort.rb:347:in `call'
    from /home/ahmad/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/tsort.rb:347:in `each_strongly_connected_component'
    from /home/ahmad/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/tsort.rb:226:in `tsort_each'
    from /home/ahmad/.rvm/rubies/ruby-3.2.1/lib/ruby/3.2.0/tsort.rb:205:in `tsort_each'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/railties-7.0.4.3/lib/rails/initializable.rb:60:in `run_initializers'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/railties-7.0.4.3/lib/rails/application.rb:372:in `initialize!'
    from /home/ahmad/Project/cuddleClone/oms-version-update/config/environment.rb:5:in `<main>'
    from config.ru:3:in `require_relative'
    from config.ru:3:in `block in <main>'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/rack-2.2.6.4/lib/rack/builder.rb:116:in `eval'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/rack-2.2.6.4/lib/rack/builder.rb:116:in `new_from_string'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/rack-2.2.6.4/lib/rack/builder.rb:105:in `load_file'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/rack-2.2.6.4/lib/rack/builder.rb:66:in `parse_file'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/rack-2.2.6.4/lib/rack/server.rb:349:in `build_app_and_options_from_config'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/rack-2.2.6.4/lib/rack/server.rb:249:in `app'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/rack-2.2.6.4/lib/rack/server.rb:422:in `wrapped_app'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/railties-7.0.4.3/lib/rails/commands/server/server_command.rb:76:in `log_to_stdout'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/railties-7.0.4.3/lib/rails/commands/server/server_command.rb:36:in `start'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/railties-7.0.4.3/lib/rails/commands/server/server_command.rb:143:in `block in perform'
    from <internal:kernel>:90:in `tap'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/railties-7.0.4.3/lib/rails/commands/server/server_command.rb:134:in `perform'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/railties-7.0.4.3/lib/rails/command/base.rb:87:in `perform'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/railties-7.0.4.3/lib/rails/command.rb:48:in `invoke'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/railties-7.0.4.3/lib/rails/commands.rb:18:in `<main>'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
    from /home/ahmad/Project/cuddleClone/oms-version-update/bin/rails:9:in `<top (required)>'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/spring-2.1.1/lib/spring/client/rails.rb:28:in `load'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/spring-2.1.1/lib/spring/client/rails.rb:28:in `call'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/spring-2.1.1/lib/spring/client/command.rb:7:in `call'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/spring-2.1.1/lib/spring/client.rb:30:in `run'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/spring-2.1.1/bin/spring:49:in `<top (required)>'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/spring-2.1.1/lib/spring/binstub.rb:11:in `load'
    from /home/ahmad/.rvm/gems/ruby-3.2.1/gems/spring-2.1.1/lib/spring/binstub.rb:11:in `<top (required)>'
    from /home/ahmad/Project/cuddleClone/oms-version-update/bin/spring:15:in `require'
    from /home/ahmad/Project/cuddleClone/oms-version-update/bin/spring:15:in `<top (required)>'
    from bin/rails:3:in `load'
    from bin/rails:3:in `<main>'

有简单的解决方法吗?

ruby-on-rails ruby devise activeadmin uninitialized-constant
2个回答
1
投票

这是一个命名错误。 Active Admin 正在搜索找不到的 SessionsController (额外的)。您应该检查会话的 Devise 控制器的命名。

也许您有

SessionController
而不是
SessionsController


0
投票

我为主动管理进行了 2FA 集成,并且它在旧版本上运行良好。我在更新 ruby 和 Rails 版本时遇到了同样的问题。我已经修好了。这是我使用的解决方案:

# 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)

我检查了设备的活动管理员最新代码 admin github repo

lib/active_admin/devise.rb
然后我据此进行了更改。

© www.soinside.com 2019 - 2024. All rights reserved.