rake db:seed NameError:rails控制台中未初始化的常量练习

时间:2016-01-18 21:48:31

标签: ruby-on-rails ruby

我正在使用课程应用来学习语言。我将众多模型迁移为课程,章节和项目(使用acts_as-active_record gem)。项目可行,课程,练习和考试 act_as 项目。 我创建了一个这样的种子:

rails = Course.create(name: "Ruby On Rails")

models = rails.chapters.create(name: "Models")

# first item is a lesson
models.items << Lesson.create(name: "What is Active Record?", content: "Lesson content here")

# then 2 exos
models.items << Exercise.create(name: "The Active Record pattern", content: "Exo about active record pattern")
models.items << Exercise.create(name: "Object Relational Mapping", content: "Exo about ORM")
models.items << Exercise.create(name: "Active Record as an ORM Framework", content: "Exo about ORM")

# a second lesson
models.items << Lesson.create(name: "Convention over Configuration in Active Record", content: "Lesson content here")

# 3 exos
models.items << Exercise.create(name: "Naming Conventions", content: "Exo about naming convention")
models.items << Exercise.create(name: "Schema Conventions", content: "Exo about schema convention")

# a summary lesson
models.items << Lesson.create(name: "Model summary", content: "Lesson content here")

# an exam
models.items << Exam.create(name: "Rails Models exam", content: "Exam content here")


# You can go to next course with : next_item = Course.first.chapters.first.items.first.lower_item
# Then go to next chapter with: next_item.chapter.lower_item

但是在我的rails控制台rake db:seed我有一个错误通知 耙子流产了! NameError:未初始化的常量练习 ../db/seeds.rb:19:in <top (required)>' -e:1:in' 任务:TOP =&gt;分贝:种子

我真的不知道错误是什么。 也许与acts_as-active_record有关系?

以下是模型:

class Course < ActiveRecord::Base 
has_many :chapters, -> { order(position: :asc) } 
validates_presence_of :title 
end 

class Chapter < ActiveRecord::Base 
acts_as_list scope: :course 
belongs_to :course 
has_many :items, -> { order(position: :asc) } 
validates_presence_of :title 
end

class Item < ActiveRecord::Base 
actable 
belongs_to :chapter 
acts_as_list scope: :chapter 
validates_presence_of :title 
end 

class Lesson < ActiveRecord::Base 
acts_as :item 
end 

class Exercise < ActiveRecord::Base 
acts_as :item 
end



class Exam < ActiveRecord::Base 
 acts_as :item 
end

整个种子都在这里。

1 个答案:

答案 0 :(得分:1)

班级ExerciceExercise不匹配。

models.items << Exercice.create(name: "The Active Record pattern", content: "Exo about active record pattern")

class Exercise < ActiveRecord::Base 
  acts_as :item 
end