0

我创建了一个新的 Rails 项目目录,并且刚刚编辑了 .gemfile;我正在阅读 Michael Hartl 的教程。我现在有了修改后的 .gemfile。它在我在命令提示符下运行的“rails generate rspec:install”旁边说明;但是,它现在给了我以下错误:

/Users/coreymkimball/Canvi/Projects/TheCanvi.com/RoR/The_Canvi/config/initializers/secret_token.rb:27:in `<top (required)>': uninitialized constant The_Canvi (NameError)
    from /Users/coreymkimball/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/railties-4.0.0/lib/rails/engine.rb:609:in `block (2 levels) in <class:Engine>'
    from /Users/coreymkimball/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/railties-4.0.0/lib/rails/engine.rb:608:in `each'
    from /Users/coreymkimball/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/railties-4.0.0/lib/rails/engine.rb:608:in `block in <class:Engine>'
    from /Users/coreymkimball/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `instance_exec'
    from /Users/coreymkimball/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `run'
    from /Users/coreymkimball/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/railties-4.0.0/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /Users/coreymkimball/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each'
    from /Users/coreymkimball/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
    from /Users/coreymkimball/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:210:in `block (2 levels) in each_strongly_connected_component_from'
    from /Users/coreymkimball/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_component_from'
    from /Users/coreymkimball/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:209:in `block in each_strongly_connected_component_from'
    from /Users/coreymkimball/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/railties-4.0.0/lib/rails/initializable.rb:44:in `each'
    from /Users/coreymkimball/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/railties-4.0.0/lib/rails/initializable.rb:44:in `tsort_each_child'
    from /Users/coreymkimball/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:203:in `each_strongly_connected_component_from'
    from /Users/coreymkimball/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component'
    from /Users/coreymkimball/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:180:in `each'
    from /Users/coreymkimball/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component'
    from /Users/coreymkimball/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
    from /Users/coreymkimball/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/railties-4.0.0/lib/rails/initializable.rb:54:in `run_initializers'
    from /Users/coreymkimball/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/railties-4.0.0/lib/rails/application.rb:215:in `initialize!'
    from /Users/coreymkimball/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/railties-4.0.0/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /Users/coreymkimball/Canvi/Projects/TheCanvi.com/RoR/The_Canvi/config/environment.rb:5:in `<top (required)>'
    from /Users/coreymkimball/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/railties-4.0.0/lib/rails/application.rb:189:in `require'
    from /Users/coreymkimball/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/railties-4.0.0/lib/rails/application.rb:189:in `require_environment!'
    from /Users/coreymkimball/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/railties-4.0.0/lib/rails/commands.rb:45:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

谁能帮帮我?

4

1 回答 1

0

查看您的错误消息,它说uninitialized constant The_Canvi。这意味着当代码运行时,它正在寻找一个具有该名称的常量(很可能是一个类),但 rails 找不到它。对于 ruby​​ 社区来说,这实际上是一个奇怪的命名约定。作为提示,在创建新的 Rails 应用程序时,您应该将应用程序的名称全部小写,然后用下划线分隔每个单词。

在您的示例中,我建议rails new the_canvi. 这将使用常量 TheCanvi 作为主应用程序类名来生成应用程序。这对于您的所有模型、控制器等都是相同的。

由于这只是一个新教程,请尝试删除该应用程序,然后重新开始。无论如何,习惯于构建一个新的应用程序总是很好的做法。

希望有帮助!

于 2013-10-01T01:39:03.597 回答