3

我正在尝试运行以下命令:

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

我不断收到这个错误:

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

这是我的 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
4

1 回答 1

8

您可能更改了 Rails 应用程序的名称。

检查config/application.rb您的应用程序的名称是否与secret_token.rb文件中使用的名称相同:

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

你应该有以下内容config/application.rb

# ...
module SampleApp
  class Application < Rails::Application
    # ...
于 2013-10-15T18:08:26.527 回答