Can I pass an argument to rake db:seed?
Asked Answered
O

1

37

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

or

$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?

Odin answered 22/1, 2013 at 2:4 Comment(1)
See also #826248Nuclei
M
59

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

and

unless ENV["minimal"]
  # do stuff

etc

Marva answered 22/1, 2013 at 2:8 Comment(1)
Beauty. Worked perfectly. Thanks.Odin

© 2022 - 2024 — McMap. All rights reserved.