2016-01-18 33 views
0

我正在學習一門課程應用程序來學習語言。我將許多模型遷移爲課程,章節和項目(使用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 

整個種子就在這裏。

+0

你可以把你的模型聲明和關係? –

+1

這可能與您無關,但練習在您的示例中拼寫錯誤。 – errata

+0

你也可以粘貼整個'db/seeds.rb'文件嗎? – pjam

回答

0

類別ExerciceExercise不匹配。

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

class Exercise < ActiveRecord::Base 
    acts_as :item 
end 
+0

它的工作原理!塔克你。我想毀掉這顆種子。你知道該怎麼辦? –

+0

如果答案正確,請接受答案。我不知道你的意思是通過銷燬種子,但是你可以通過在你的控制檯輸入''rake db:drop''然後'rake db:migrate'來重置數據庫(假設你使用的是sqlite/postgres ) – apebeast

+0

是的,但我想只是添加一個按鈕刪除或方法來摧毀它在我的秀#視圖。我想我不清楚我的問題,對不起。 –

相關問題