Reputation: 651
I am trying to make a custom rake
task, but I cannot seem to get it working. My code looks like this:
namespace :demotask do
desc "display the current environment of rake"
task :current_environment => :environment do
puts "You are running rake task in #{Rails.env} environment"
end
end
and is placed in a file named test.rake
under lib/tasks
. The Rakefile
is there, but I do get this error when running the task in the console:
NameError: undefined local variable or method 'current_environment' for main:Object
I tried to restart the server as well.
Upvotes: 3
Views: 5207
Reputation: 7043
You should use the namespace
to call it from the terminal, and probably it's a good idea to use bundler
:
bundle exec rake demotask:current_environment
Also, try to change task definition to:
task :current_environment => :environment do
...
Including => :environment
will tell Rake to load the full application environment.
Upvotes: 5