播种数据库时忽略单个夹具文件

Ignoring a single fixture file while seeding database

我在 heroku 上托管一个用 rails 编写的项目。 我有一个在测试期间使用的夹具文件 (comments.yml),但我不想在为我的数据库做种时包含它(通过 'heroku run rails db:seed')。

如何与 heroku 沟通我希望它在播种时忽略 'comments.yml'?

您可以使用环境变量并在您的种子脚本中控制它:

rake db:seed comments=true

稍后在您的 seeds.rb 中:

unless ENV["comments"]