由于设计,来自模板的新 rails 应用程序失败

New rails app from template fails because of devise

我创建了一个 rails 应用程序模板 (https://github.com/alec-c4/kickstart) 并且我使用设计 gem 作为身份验证解决方案。一切正常,但有时新的应用程序生成器崩溃

    generate  migration EnableTrgmPsqlExtension
       rails  generate migration EnableTrgmPsqlExtension
/Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activerecord-6.1.4/lib/active_record/dynamic_matchers.rb:22:in `method_missing': undefined method `devise' for User:Class (NoMethodError)
    from /Users/alec/Temp/youre_not_alone/app/models/user.rb:6:in `<class:User>'
    from /Users/alec/Temp/youre_not_alone/app/models/user.rb:1:in `<main>'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:26:in `require'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activesupport-6.1.4/lib/active_support/inflector/methods.rb:274:in `const_get'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activesupport-6.1.4/lib/active_support/inflector/methods.rb:274:in `constantize'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activesupport-6.1.4/lib/active_support/dependencies/zeitwerk_integration.rb:19:in `constantize'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/bundler/gems/devise-c82e4cf47b02/lib/devise.rb:316:in `get'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/bundler/gems/devise-c82e4cf47b02/lib/devise/mapping.rb:83:in `to'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/bundler/gems/devise-c82e4cf47b02/lib/devise/mapping.rb:78:in `modules'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/bundler/gems/devise-c82e4cf47b02/lib/devise/mapping.rb:95:in `routes'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/bundler/gems/devise-c82e4cf47b02/lib/devise/mapping.rb:162:in `default_used_route'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/bundler/gems/devise-c82e4cf47b02/lib/devise/mapping.rb:72:in `initialize'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/bundler/gems/devise-c82e4cf47b02/lib/devise.rb:346:in `new'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/bundler/gems/devise-c82e4cf47b02/lib/devise.rb:346:in `add_mapping'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/bundler/gems/devise-c82e4cf47b02/lib/devise/rails/routes.rb:243:in `block in devise_for'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/bundler/gems/devise-c82e4cf47b02/lib/devise/rails/routes.rb:242:in `each'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/bundler/gems/devise-c82e4cf47b02/lib/devise/rails/routes.rb:242:in `devise_for'
    from /Users/alec/Temp/youre_not_alone/config/routes.rb:6:in `block in <main>'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/actionpack-6.1.4/lib/action_dispatch/routing/route_set.rb:427:in `instance_exec'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/actionpack-6.1.4/lib/action_dispatch/routing/route_set.rb:427:in `eval_block'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/actionpack-6.1.4/lib/action_dispatch/routing/route_set.rb:409:in `draw'
    from /Users/alec/Temp/youre_not_alone/config/routes.rb:3:in `<main>'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:59:in `load'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:59:in `load'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/railties-6.1.4/lib/rails/application/routes_reloader.rb:47:in `block in load_paths'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/railties-6.1.4/lib/rails/application/routes_reloader.rb:47:in `each'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/railties-6.1.4/lib/rails/application/routes_reloader.rb:47:in `load_paths'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/railties-6.1.4/lib/rails/application/routes_reloader.rb:21:in `reload!'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/railties-6.1.4/lib/rails/application/routes_reloader.rb:35:in `block in updater'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activesupport-6.1.4/lib/active_support/file_update_checker.rb:83:in `execute'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/railties-6.1.4/lib/rails/application/routes_reloader.rb:10:in `execute'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/railties-6.1.4/lib/rails/application/finisher.rb:208:in `block (2 levels) in <module:Finisher>'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activesupport-6.1.4/lib/active_support/callbacks.rb:427:in `instance_exec'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activesupport-6.1.4/lib/active_support/callbacks.rb:427:in `block in make_lambda'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activesupport-6.1.4/lib/active_support/callbacks.rb:198:in `block (2 levels) in halting'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activesupport-6.1.4/lib/active_support/callbacks.rb:604:in `block (2 levels) in default_terminator'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activesupport-6.1.4/lib/active_support/callbacks.rb:603:in `catch'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activesupport-6.1.4/lib/active_support/callbacks.rb:603:in `block in default_terminator'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activesupport-6.1.4/lib/active_support/callbacks.rb:199:in `block in halting'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activesupport-6.1.4/lib/active_support/callbacks.rb:512:in `block in invoke_before'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activesupport-6.1.4/lib/active_support/callbacks.rb:512:in `each'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activesupport-6.1.4/lib/active_support/callbacks.rb:512:in `invoke_before'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activesupport-6.1.4/lib/active_support/callbacks.rb:105:in `run_callbacks'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activesupport-6.1.4/lib/active_support/execution_wrapper.rb:111:in `run!'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activesupport-6.1.4/lib/active_support/reloader.rb:114:in `run!'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activesupport-6.1.4/lib/active_support/reloader.rb:53:in `block (2 levels) in reload!'
    from <internal:kernel>:90:in `tap'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activesupport-6.1.4/lib/active_support/reloader.rb:52:in `block in reload!'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activesupport-6.1.4/lib/active_support/execution_wrapper.rb:88:in `wrap'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/activesupport-6.1.4/lib/active_support/reloader.rb:51:in `reload!'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/spring-2.1.1/lib/spring/application.rb:168:in `serve'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/spring-2.1.1/lib/spring/application.rb:145:in `block in run'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/spring-2.1.1/lib/spring/application.rb:139:in `loop'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/spring-2.1.1/lib/spring/application.rb:139:in `run'
    from /Users/alec/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/spring-2.1.1/lib/spring/application/boot.rb:19:in `<top (required)>'
    from <internal:/Users/alec/.rbenv/versions/3.0.1/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
    from <internal:/Users/alec/.rbenv/versions/3.0.1/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
    from -e:1:in `<main>'

我已经通过在 user.rb 文件中添加

行解决了这个问题
extend Devise::Models

但它看起来是一种解决方法,而不是永久解决方案。知道如何解决吗?

认为您可能需要 运行 生成器,以便它可以创建设计初始化文件。 /config/initializers/devise.rb

rails generate devise:install

如果上述崩溃,您可能需要注释掉 User.rb 中的 devise :database_authenti... 行并再次 运行 生成器

我正在通过 phone 查看您的代码,所以请原谅任何错误 :)