在Rails中运行rake命令时未初始化的常量

时间:2014-06-25 16:45:02

标签: ruby ruby-on-rails-3 rake

我正在尝试按照本教程http://tutorials.jumpstartlab.com/projects/blogger.html进行操作。 当我运行rake db:migrate时,我得到了

rake aborted!
NameError: uninitialized constant CreateArticles
/home/nbandy/.rvm/gems/ruby-2.0.0-p481/gems/activesupport-4.1.1/lib/active_support/inflector/methods.rb:238:in `const_get'
/home/nbandy/.rvm/gems/ruby-2.0.0-p481/gems/activesupport-4.1.1/lib/active_support/inflector/methods.rb:238:in `block in constantize'
/home/nbandy/.rvm/gems/ruby-2.0.0-p481/gems/activesupport-4.1.1/lib/active_support/inflector/methods.rb:236:in `each'
/home/nbandy/.rvm/gems/ruby-2.0.0-p481/gems/activesupport-4.1.1/lib/active_support/inflector/methods.rb:236:in `inject'
/home/nbandy/.rvm/gems/ruby-2.0.0-p481/gems/activesupport-4.1.1/lib/active_support/inflector/methods.rb:236:in `constantize'
/home/nbandy/.rvm/gems/ruby-2.0.0-p481/gems/activesupport-4.1.1/lib/active_support/core_ext/string/inflections.rb:66:in `constantize'
/home/nbandy/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.1.1/lib/active_record/migration.rb:762:in `load_migration'
/home/nbandy/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.1.1/lib/active_record/migration.rb:757:in `migration'
/home/nbandy/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.1.1/lib/active_record/migration.rb:752:in `disable_ddl_transaction'
/home/nbandy/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.1.1/lib/active_record/migration.rb:1045:in `use_transaction?'
/home/nbandy/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.1.1/lib/active_record/migration.rb:955:in `rescue in block in migrate'
/home/nbandy/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.1.1/lib/active_record/migration.rb:952:in `block in migrate'
/home/nbandy/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.1.1/lib/active_record/migration.rb:949:in `each'
/home/nbandy/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.1.1/lib/active_record/migration.rb:949:in `migrate'
/home/nbandy/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.1.1/lib/active_record/migration.rb:807:in `up'
/home/nbandy/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.1.1/lib/active_record/migration.rb:785:in `migrate'
/home/nbandy/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.1.1/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
/home/nbandy/.rvm/gems/ruby-2.0.0-p481/bin/ruby_executable_hooks:15:in `eval'
/home/nbandy/.rvm/gems/ruby-2.0.0-p481/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

过去四个小时我一直在寻找答案,但没有人帮助过。在谈到这一点时,我是一个绝对的初学者,所以我确信答案比我想象的更明显。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

检查以下文件以及命名的完成方式。惯例应该是:

/models/article.rb

class Article < ActiveRecord::Base
...

/db/migrate/20140625123456_create_articles.rb

class CreateArticles < ActiveRecord::Migration
...