2

I have a rake task to populate my db which depends on faker, so at the top there's:

require 'faker'

The problem is I don't install faker in production so all rake commands (like db:migrate) fail on that require line, saying faker is missing.

Obviously I could install faker in production to get around this, but I don't need it there. So what's the right solution -- can I somehow ignore certain rake tasks in production?

tyson
  • 23
  • 2

2 Answers2

6

Move the require statement into the task which actually needs it.

Simone Carletti
  • 173,507
  • 49
  • 363
  • 364
2

I suppose you could just do require 'faker' unless RAILS_ENV='production'

Martin Svalin
  • 2,227
  • 1
  • 17
  • 23
  • 2
    That's not a clean solution because what happens if you decide you need that task in `staging`? In this case you can detach the task from the environment, just move the require within the task that needs it. – Simone Carletti Nov 19 '10 at 11:47