Ruby on Rails: loading seed data from a YAML file

后端 未结 4 951
礼貌的吻别
礼貌的吻别 2020-12-28 18:04

How do I use a YAML file instead of seeds.rb to load the initial data into a database?

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-28 18:12

    Check out the Ruby on Rails Guide to fixtures:

    http://guides.rubyonrails.org/testing.html#the-low-down-on-fixtures

    Generally, you can create YAML fixture files in the test/ directory and then load them into your database using the rake db:fixtures:load command. The full documentation on all the cool things you can do with fixtures is here:

    http://api.rubyonrails.org/classes/Fixtures.html

提交回复
热议问题