开发者

rails how to automatic generate some data to db for developing [closed]

开发者 https://www.devze.com 2023-01-28 09:00 出处:网络
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this
Closed. This question needs to be more focused. It is not currently accepting answers.

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 8 years ago.

Improve this question

for the develop 开发者_如何学Crequire ,we always need some fake data, so i want to know is there some way to quick generate data to db, then we can test it as soon as possible


I'd go to factory girl gem, which allows you to create data blueprints to generate data easily:

https://github.com/thoughtbot/factory_girl

or Machinist: https://github.com/notahat/machinist

I personnaly use Machinist, but I know a lot of people like Factory Girl.


you can use Faker gem (here is how to do it)


You have a file in you rails_app/db directory called seed.rb You can put your initial data there.

Have a look at this railscasts #179 => Seed Data

After putting dummy data in the file you can run the rake command rake db:seed this will put all the contents of your seed.rb file in your database and create initial records to play with. :D


Faker is what I generally use to seed the database. Here is the Michael Hartl Rails Tutorial Link on how to set it up.

http://www.railstutorial.org/book/updating_and_deleting_users#cha-updating_showing_and_deleting_users

Section 9.3.2

Also checkout the github page for other options of items you can generate, but this is a great quick and easy how to.

0

精彩评论

暂无评论...
验证码 换一张
取 消