2016-01-19 54 views
2

您好,当我想rake db:seed在我的控制台出现此唯一的消息导轨 - 通过Spring预加载过程8773运行 - 在我的控制台

通过弹簧预加载在进程中运行8773

待办事项你我该如何创造我的种子?当我将它部署到heroku master时,它不会出现?

这里是种子:

rails = Course.create(title: "Ruby On Rails") 
models = rails.chapters.create(title: "Models") 

models.items << Lesson.create(title: "What is Active Record?", content: "Lesson content here") 

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

models.items << Lesson.create(title: "Convention over Configuration in Active Record", content: "Lesson content here") 

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

models.items << Lesson.create(title: "Model summary", content: "Lesson content here") 

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

我想将它保存修复它的第一期培训班,并删除它摧毁它,当我完成了最后的版本。我试图推动它heroku但种子消失。你知道为什么吗?

+0

转到db/seeds.rb并把它放在底部''puts puts“done”'''。现在重新运行您的命令以确认种子未运行 – MilesStanfield

+0

它的工作原理@MilesStanfield。 –

回答

1

我觉得自述说明了什么春天是最好的

Spring是一个Rails应用程序预加载。它通过保持应用程序在后台运行来加速开发,因此无需在每次运行测试,耙取任务或迁移时都引导它。

因此,您只能在您的本地计算机上看到此命令,因为Heroku未使用Spring(或任何其他主机)。

,因为你不printputs东西在你seeds.rb没有出现在屏幕上,但它很可能是很好的为Rails让你知道,这是成功的!

您可以随时检查,如果种子数据已成功通过检查什么在你的数据库加载,例如

Course.first.title 
=> "Ruby On Rails" 
Lesson.first.title 
=> "What is Active Record?" 

+0

好@MichalSzyndel,但是如果种子不能做到这一点,我该如何显示一个真正的课程?我必须在我的模型中创建它? –

+0

我不明白你的意思? –

+0

我的意思是我想在MVC中创建课程(不在种子中)我在哪里创建我的标题和我的内容=>在我的视图中? –

0

弹簧预加载仅用于开发,它没有必要也没有用生产,因此没有关于它的消息。

你的代码本身不输出任何东西,这就是为什么你没有看到它。

我建议更改为create!,以便在发生错误时会出现异常和大量输出。

+0

谢谢@Vasfed是否​​将.create改为.create!在所有创造使用在种子? –

+0

@BaptisteB。是的,否则没有什么会被默默保存,因为你的代码不检查返回值 – Vasfed

+0

谢谢。我怎样才能摧毁这颗种子?我是否将rails = Course.destroy? –