尝试在 Rails 7.0.0 上的 Ruby 中安装设计时出错

Error when trying to install devise in Ruby on Rails 7.0.0

我正在尝试在 rails 版本中安装 devise 我收到最新版本 devise 的错误消息

我尝试过其他版本的设备,但它已更新到最新版本,

这是错误:

/usr/local/bundle/gems/devise-4.8.0/lib/devise.rb:321:in `ref': undefined method `reference' for ActiveSupport::Dependencies:Module (NoMethodError)
web_1  |    from /usr/local/bundle/gems/devise-4.8.0/lib/devise.rb:340:in `mailer='
web_1  |    from /usr/local/bundle/gems/devise-4.8.0/lib/devise.rb:342:in `<module:Devise>'
web_1  |    from /usr/local/bundle/gems/devise-4.8.0/lib/devise.rb:11:in `<main>'
web_1  |    from /usr/local/bundle/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
web_1  |    from /usr/local/bundle/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
web_1  |    from /usr/local/bundle/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
web_1  |    from /usr/local/bundle/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
web_1  |    from /usr/local/bundle/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
web_1  |    from /usr/local/bundle/gems/zeitwerk-2.5.0.beta3/lib/zeitwerk/kernel.rb:35:in `require'
web_1  |    from /usr/local/lib/ruby/3.0.0/bundler/runtime.rb:66:in `block (2 levels) in require'
web_1  |    from /usr/local/lib/ruby/3.0.0/bundler/runtime.rb:61:in `each'
web_1  |    from /usr/local/lib/ruby/3.0.0/bundler/runtime.rb:61:in `block in require'
web_1  |    from /usr/local/lib/ruby/3.0.0/bundler/runtime.rb:50:in `each'
web_1  |    from /usr/local/lib/ruby/3.0.0/bundler/runtime.rb:50:in `require'
web_1  |    from /usr/local/lib/ruby/3.0.0/bundler.rb:174:in `require'

如果你能帮助我,我将不胜感激

错误来源

您使用的 Devise 版本调用了一个名为 reference 的方法。 https://github.com/heartcombo/devise/blob/c82e4cf47b02002b2fd7ca31d441cf1043fc634c/lib/devise.rb#L320-L323

def self.ref(arg)
  ActiveSupport::Dependencies.reference(arg)
  Getter.new(arg)
end

方法存在于Rails6: https://github.com/rails/rails/blob/6-0-stable/activesupport/lib/active_support/dependencies.rb#L651-L653

它已在 Rails 7 中删除: https://github.com/rails/rails/blob/main/activesupport/lib/active_support/dependencies.rb

Rails 7.0.0.alpha1 变更日志中的这一行进行了解释。

Private internal classes of ActiveSupport::Dependencies have been deleted, like ActiveSupport::Dependencies::Reference, ActiveSupport::Dependencies::Blamable, and others.

https://github.com/rails/rails/blob/main/activesupport/CHANGELOG.md#rails-700alpha1-september-15-2021

修复:升级 Devise

设备有 released a 4.8.1 版本兼容 Rails 7. 运行 bundle update devise 升级。

此修复修复了我的错误:

gem "devise", github: "strobilomyces/devise", branch: "patch-1"

https://github.com/heartcombo/devise/pull/5397

Devise 已经将此问题的修复程序与 rails 7 合并到他们的主要分支。

在发布新版本之前,您可以将设备 gem 指向 Gemfile 中来自 GitHub 的主分支:

gem 'devise', git: 'https://github.com/heartcombo/devise', branch: 'main'