简体   繁体   English

未初始化的常量SampleApp(NameError)

[英]uninitialized constant SampleApp (NameError)

I'm trying to run the following command: 我正在尝试运行以下命令:

rails generate controller StaticPages home help --no-test-framework

And I keep getting this error: 我一直收到这个错误:

/Users/josh/Desktop/RoR/rails_app/config/initializers/secret_token.rb:27:in `<top (required)>': uninitialized constant SampleApp (NameError)

Here's my secret_token.rb file 这是我的secret_token.rb文件

require 'securerandom'

def secure_token
  token_file = Rails.root.join('.secret')
  if File.exist?(token_file)
    # Use the existing token.
    File.read(token_file).chomp
  else
    # Generate a new token and store it in token_file.
    token = SecureRandom.hex(64)
    File.write(token_file, token)
    token
  end
end

SampleApp::Application.config.secret_key_base = secure_token

You probably change the name of your Rails application. 您可能更改了Rails应用程序的名称。

Check in config/application.rb that the name of your application is the same that the one use in your secret_token.rb file: 检入config/application.rb ,确认config/application.rb的名称与secret_token.rb文件中的名称相同:

SampleApp::Application.config.secret_key_base = secure_token
^^^^^^^^^

You should have the following in config/application.rb : 您应该在config/application.rb包含以下内容:

# ...
module SampleApp
  class Application < Rails::Application
    # ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM