Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 Rails 中,可以使用 ? 以外的文件为数据库播种db/seeds.rb?
db/seeds.rb
rake db:reset如在,是否有某种方法可以在运行时指定备用种子文件rake db:reset --seedwith db/seeds2.rb?
rake db:reset
rake db:reset --seedwith db/seeds2.rb
您可以使用环境变量将开关传递到seeds.rb,并相应地播种不同的数据。
SEED_DATA=set1 rake db:seed SEED_DATA=set2 rake db:seed
在种子.rb 中,
if ENV['SEED_DATA'] == 'set1' ... elsif ENV['SEED_DATA'] == 'set2' ... else ... end