【发布时间】:2011-12-28 22:44:21
【问题描述】:
我正在使用 seed.rb 来填充我的开发和生产数据库。我通常用虚拟数据填充第一个数据,然后用我的应用程序需要运行的真实最小数据(例如第一个用户等)填充后者。
如何在 seed.rb 中指定每个数据的环境?
鉴于我知道“组”是一个 Gemfile 方法,我想为 seed.rb 实现相同的行为。
例如我想在我的seed.rb中写这样的东西:
group :development do
# development specific seeding code
end
group :production do
# production specific seeding code
end
# non-specific seeding code (it always runs)
这样可以同时调用开发特定和非特定代码
$ rake db:seed
并调用生产特定和非特定代码:
$ rake db:seed RAILS_ENV=production
谢谢
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 environment