gpt4 book ai didi

ruby-on-rails - rails g mongoid :config not working Rails 6. 1

转载 作者:行者123 更新时间:2023-12-03 15:34:17 25 4
gpt4 key购买 nike

我在 Mac Sierra 上使用 Rails 6.1,并尝试安装 MongoDB 作为数据库,
已经在 bash 和 gem 上安装了 mongo db 服务,但是当我输入时:

bin/rails g mongoid:config
它显示以下错误:
Traceback (most recent call last):
26: from bin/rails:5:in `<main>'
25: from /Users/guilherme/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:332:in `require'
24: from /Users/guilherme/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:299:in `load_dependency'
23: from /Users/guilherme/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:332:in `block in require'
22: from /Users/guilherme/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
21: from /Users/guilherme/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
20: from /Users/guilherme/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
19: from /Users/guilherme/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
18: from /Users/guilherme/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
17: from /Users/guilherme/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/railties-6.1.0/lib/rails/commands.rb:18:in `<main>'
16: from /Users/guilherme/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/railties-6.1.0/lib/rails/command.rb:50:in `invoke'
15: from /Users/guilherme/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/railties-6.1.0/lib/rails/command/base.rb:69:in `perform'
14: from /Users/guilherme/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/thor-1.0.1/lib/thor.rb:392:in `dispatch'
13: from /Users/guilherme/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/thor-1.0.1/lib/thor/invocation.rb:127:in `invoke_command'
12: from /Users/guilherme/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/thor-1.0.1/lib/thor/command.rb:27:in `run'
11: from /Users/guilherme/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/railties-6.1.0/lib/rails/commands/generate/generate_command.rb:26:in `perform'
10: from /Users/guilherme/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/railties-6.1.0/lib/rails/generators.rb:275:in `invoke'
9: from /Users/guilherme/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/thor-1.0.1/lib/thor/base.rb:485:in `start'
8: from /Users/guilherme/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/thor-1.0.1/lib/thor/group.rb:232:in `dispatch'
7: from /Users/guilherme/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/thor-1.0.1/lib/thor/invocation.rb:134:in `invoke_all'
6: from /Users/guilherme/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/thor-1.0.1/lib/thor/invocation.rb:134:in `map'
5: from /Users/guilherme/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/thor-1.0.1/lib/thor/invocation.rb:134:in `each'
4: from /Users/guilherme/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/thor-1.0.1/lib/thor/invocation.rb:134:in `block in invoke_all'
3: from /Users/guilherme/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/thor-1.0.1/lib/thor/invocation.rb:127:in `invoke_command'
2: from /Users/guilherme/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/thor-1.0.1/lib/thor/command.rb:27:in `run'
1: from /Users/guilherme/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/bundler/gems/mongoid-3c6bdaced7d8/lib/rails/generators/mongoid/config/config_generator.rb:18:in `app_name'
/Users/guilherme/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/railties-6.1.0/lib/rails/railtie.rb:209:in method_missing': undefined method Code7::Application:Class 的父级(NoMethodError)
你的意思是?展示?
试图停止 Spring 服务器,没有成功。
这是 gemfile
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.7.2'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.1.0'
# Use Puma as the app server
gem 'puma', '~> 5.0'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
# gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# MongoDB
gem 'mongoid', git: 'https://github.com/mongodb/mongoid.git', branch: 'master'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.4', require: false

# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
# gem 'rack-cors'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
gem 'listen', '~> 3.3'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
# gem 'spring'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
提前致谢!

最佳答案

只是一个解决方法

  • 打开config_generator.rb(根据自己机器改路径)

  • nano /usr/local/bundle/bundler/gems/mongoid-d673c43e8846/lib/rails/generators/mongoid/config/config_generator.rb`


  • 替换

  • def app_name
    Rails::Application.subclasses.first.parent.to_s.underscore
    end

    为了
    def app_name
    Rails::Application.subclasses.first.to_s.split('::').first
    end

    或者
    def app_name
    'your_app_name'
    end

    不确定这以后会不会有副作用,但至少我可以运行它

    关于ruby-on-rails - rails g mongoid :config not working Rails 6. 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65523055/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com