Ruby on Rails中的db文件夹中的seeds.rb是什么?

时间:2015-05-23 09:28:17

标签: ruby-on-rails

db / seeds.rb和db / schema.rb之间的关系是什么?我如何使用它们?顺便说一句,

# db/seeds.rb

Todo.create!(title: 'grocery shopping', notes: 'pickles, eggs, red onion')
Todo.create!(title: 'wash the car')
Todo.create!(title: 'register kids for school', notes: 'Register Kira for Ruby Junior High and Caleb for Rails High School')
Todo.create!(title: 'check engine light', notes: 'The check engine light is on in the Tacoma')
Todo.create!(title: 'dog groomers', notes: 'Take Pinky and Redford to the groomers on Wednesday the 23rd')

我无法理解'笔记'

2 个答案:

答案 0 :(得分:1)

seed.rb 可帮助您将数据初始化到数据库中。

您可以通过以下方式运行该文件:

rake db:seed

或运行

rake db:setup

创建数据库,运行迁移和运行种子

答案 1 :(得分:0)

假设您创建了一个 db,您可以用seeds.rb 填充它。换句话说,您根据事先生成的模型填充表格。

User.create (username: "tony", password: "12345666")
User.create (username: "Clara", password: "fdvfdvfd666")
User.create (username: "Hans", password: "1gbfdbg2345666")