我正在學習一門課程應用程序來學習語言。我將許多模型遷移爲課程,章節和項目(使用acts_as-active_record gem)。項目是可執行和課,練習和考試是act_as項目。 我創建了一個種子是這樣的:rake db:seed NameError:未初始化的常量在rails控制檯中的練習
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控制檯耙分貝:種子我有通知 耙中止錯誤! NameError:未初始化不斷Exercice ../db/seeds.rb:19:in <top (required)>' -e:1:in
「 任務:TOP => DB:種子
我真的不知道什麼是錯誤。 也許與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
整個種子就在這裏。
你可以把你的模型聲明和關係? –
這可能與您無關,但練習在您的示例中拼寫錯誤。 – errata
你也可以粘貼整個'db/seeds.rb'文件嗎? – pjam