rake file created not recognized by rake -T

I am trying to write a custom rake task for my app. But however simple
my rake task is, rake -T still does not list it. Here's my file in
/lib/tasks called try.rake:

desc "try rake"
task :one do
puts "task one"
end

and therefore when I run rake try.one I get the "Don't know how to build
task 'try,one'... Anything else need to be configured to get custom
rake task to work?
Please help. Thanks!

For creating rake tasks, you need to first create a namespace.

The following is an example of how to do what you want to do :

namespace :tasks do

desc “try rake”

task :one => :environment do

puts “task one”

end

end

Once you have this in your try.rake file in /lib/tasks

when you do a rake -T , it will show you your custom rake tasks in the following way :

rake tasks:one

and that is how you need to call it to execute the rake task as well.

I hope that helps.

Thanks & Regards,

Dhruva Sagar.

Marie von Ebner-Eschenbach - “Even a stopped clock is right twice a day.”

Kevin,

/lib/tasks called try.rake:

desc "try rake"
task :one do
puts "task one"
end

Assuming the file is named "#{RAILS_ROOT}/lib/tasks/try.rake", all
this is fine.

You don't need to use namespaces if you don't want to.

Don't know how to build task 'try,one'

You should have a task named "one" showing up in the -T list, 'try'
will not be part of the task name unless you specify a namespace.

Bryan

Thanks & Regards,
Dhruva Sagar.

Joan Crawford - “I, Joan Crawford, I believe in the dollar. Everything I earn, I spend.”

Kevin,

/lib/tasks called try.rake:

desc “try rake”

task :one do

puts “task one”

end

Assuming the file is named “#{RAILS_ROOT}/lib/tasks/try.rake”, all

this is fine.

You don’t need to use namespaces if you don’t want to.

OK, my bad, I thought in order to be part of -T list, you need to have a namespace.