Reputation: 33
i've got several tasks like this:
desc "Generate and send something"
task(:generate_something => :environment) do
Those were situtated in lib/tasks
Is there any possibility to don't set up the environment? I want that the task find out by it selve which environment is active at the moment?
Upvotes: 1
Views: 26
Reputation: 6126
You can simply test the Rails.env
variable as in the app itself:
desc "Test task"
task :blaff do
puts Rails.env
puts Rails.env.production?
end
Now you can run this in any environment you want:
% rake blaff
development
false
% RAILS_ENV=production rake blaff
production
true
% RAILS_ENV=test rake blaff
test
false
Upvotes: 1