耙 db:种子 名称错误:未初始化的常量 在 rails 控制台中锻炼



我正在开发一个课程应用程序来学习语言。我将许多模型迁移为课程、章节和项目(使用 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 控制台中,耙 db:seed 我有一个错误,它通知耙子中止了!名称错误: 未初始化的常量执行../db/seeds.rb:19:in <top (required)>' -e:1:in '任务:顶部 => 数据库:种子

我真的不知道错误是什么。也许与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

整个种子都在这里。

ExerciceExercise不匹配。

models.items << Exercice.create(name: "The Active Record pattern", content: "Exo about active record pattern")
class Exercise < ActiveRecord::Base 
  acts_as :item 
end

最新更新