gpt4 book ai didi

ruby-on-rails - 设置 Figaro gem 时未初始化的常量项目 (NameError)

转载 作者:行者123 更新时间:2023-12-04 05:49:13 25 4
gpt4 key购买 nike

我将 Rails 2.3 应用程序更新到 3.2,这似乎是一个非常简单的过程,但是在设置 Figaro gem 时我遇到了这个错误:

C:\Sites\JustManage>rails generate figaro:install
C:/Sites/JustManage/config/environment.rb:5:in `<top (required)>': uninitialized
constant Projectmanagement (NameError)
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1
/lib/rails/application.rb:103:in `require_environment!'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1
/lib/rails/commands.rb:25:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

这是我的 environment.rb 的样子:

# Load the rails application
require File.expand_path('../application', __FILE__)

# Initialize the rails application
Projectmanagement::Application.initialize!

这是我的application.rb 文件:

require File.expand_path('../application', __FILE__)

require 'rails/all'

if defined?(Bundler)
Bundler.require(*Rails.groups(:assets => %w(development test)))
end

module Railsapp
class Application < Rails::Application
config.encoding = "utf-8"

config.filter_parameters += [
:password,
:password_clear,
:password_verify
]

config.assets.enabled = true
config.assets.version = '1.0'

end
end

我以前从未遇到过这个错误,也不知道为什么会这样。

最佳答案

您的应用程序的名称似乎在它需要出现的不同位置不相同。检查以下文件并查看它们是否包含 Projectmanagement::Application Railsapp::应用程序:

  • config/application.rb(实际初始化常量)
  • config/environment.rb
  • config/environments/development.rb
  • config/environments/production.rb
  • 配置/环境/test.rb
  • config/initializers/secret_token.rb
  • config/initializers/session_store.rb
  • config/mongoid.yml(如果使用 Mongoid)
  • config/routes.rb
  • config.ru
  • 梳理文件
  • app/views/layouts/application.html.erb,在标题标签中

然后选择一个名称(ProjectmanagementRailsapp)并更改上述文件中的所有名称,使它们匹配。这应该可以解决您遇到的未初始化常量错误。

关于ruby-on-rails - 设置 Figaro gem 时未初始化的常量项目 (NameError),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20366577/

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