How Do I Add Custom Rake Tasks to My Project?
You can add tasks to the existing Rakefile which is in the project's root folder.
If you have have a set of tasks that you use across Rails projects, you can put them a file named Rakefile or a file with a .rake extension and add the file to the Libs > tasks folder in your project.
- To create a Rakefile file, right-click the project node and choose New > Other . Select the Ruby category and select the Rakefile file type.
- To create a .rake file, right-click the project node and choose New > Other . Select the Other category and select the Empty File file type. When you name the file, give it the .rake extension. (Note: There is a bug filed to add support for the .rake extension.)
Put the file in the Libs > tasks folder so the file is automatically available to Rake.
To make a custom task appear in the Run Rake Task pop-up menu, the task must have a description (see the example below). The assumption is that non-documented targets are implementation targets and the documented ones are the ones you want to expose.
To make newly created custom tasks appear in the menu, right-click the project node and choose Run Rake Task > Refresh List.
To test this out, add the following task to either the Rakefile or to a .rake file in lib/tasks in a Rails project. Right-click the Projects node and choose Run Rake Task > Refresh List. Then choose Run Rake Task > db > schema_version. (Note: this task was taken from the Depot sample application).
namespace :db do desc "Prints the migration version" task :schema_version => :environment do puts ActiveRecord::Base.connection.select_value('select version from schema_info') end end
If you have ideas of what to put in the generated Rakefile, you can add them to bug 117668.