我可以将参数传递给rake db:seed吗? [英] Can I pass an argument to rake db:seed?

查看:130
本文介绍了我可以将参数传递给rake db:seed吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的seeds.rb的一部分将大量数据加载到数据库中.我希望能够有选择地加载此数据.例如.

Part of my seeds.rb loads a lot of data into the database. I want to be able to selectively load this data. E.g.

$ rake db:seed

$rake db:seed[0]

只需加载必要的数据即可运行该网站,而

would just load the necessary data to run the site, while

$ rake db:seed[1]

也将我的大数据文件加载到数据库中.这可能吗?我怎样才能做到这一点?如果没有,谁能想到一种方法来做我想做的事?

would load my big data file into the database as well. Is this possible? How can I make this happen? If not, can anyone think of a way to do what I'm trying to do?

推荐答案

Rake参数很难传递(而且

Rake arguments are painful to pass around, unfortunately (and db:seed doesn't pass its arguments through, regardless).

您最好的选择是使用环境变量通过以下方式传递额外的参数:

Your best bet is to use environment variables to pass your extra args through:

rake db:seed minimal=yes

unless ENV["minimal"]
  # do stuff

这篇关于我可以将参数传递给rake db:seed吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆