2013-10-15 57 views
3

我试图运行下面的命令:未初始化的常量SampleApp(NameError)

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 
+0

在'Rake文件什么'?我想检查应用名称是否匹配。 – HungryCoder

+1

您的应用名为SampleApp,还是称为RailsApp? – trh

+0

比较'config/application.rb'中应用的名称。这可能与'SampleApp'有所不同! – ck3g

回答

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 
    # ... 
+0

谢谢!它现在有效! – josmek

相关问题