Rails错误 - 未初始化常量

3

在新建一个rails项目时,我遇到了以下问题:

当执行rails s命令时出现了如下错误:

john-MacBook-Pro:coffee john$ rails s
/Users/john/Development/coffee/config/application.rb:10:in `<module:Coffee>': uninitialized constant Coffee::Rails::Application (NameError)
    from /Users/john/Development/coffee/config/application.rb:9:in `<top (required)>'
    from /Users/john/.rvm/gems/ruby-2.1.2/gems/railties-4.0.3/lib/rails/commands.rb:74:in `require'
    from /Users/john/.rvm/gems/ruby-2.1.2/gems/railties-4.0.3/lib/rails/commands.rb:74:in `block in <top (required)>'
    from /Users/john/.rvm/gems/ruby-2.1.2/gems/railties-4.0.3/lib/rails/commands.rb:71:in `tap'
    from /Users/john/.rvm/gems/ruby-2.1.2/gems/railties-4.0.3/lib/rails/commands.rb:71:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

这到底是什么原因造成的,我该如何修复它?

谢谢您的关注。

Application.rb 文件:

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

require 'rails/all'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)

module Coffee
  class Application < Rails::Application
    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.

    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
    # config.time_zone = 'Central Time (US & Canada)'

    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
    # config.i18n.default_locale = :de
  end
end

你能发布你的application.rb文件吗? - thaleshcv
希望您正在代码所在的文件夹中运行此命令 :) - Milind
添加了代码 @thaleshcv - RubyMax
1个回答

10
您似乎将应用程序命名为“coffee”。这意味着您在config/application.rb文件中声明了一个名为module Coffee的模块。
Rails使用coffee-rails gem来支持Rails应用程序中的咖啡脚本,并且它也声明了一个名为module Coffee的模块。
您不小心创建了一个与应用程序名称相冲突的名称。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接