Add sub-task rake

rake, ruby-on-rails

Solution

Use the `namespace` directive:

namespace :db do
  namespace :seed do
    task :demo do
    end
  end
end

Problem

I'm using rails 4 and I need to add a subtask for seeding our database using demo data (for product demo's). I want to make it a subtask called `rake db:seed:demo`, how can I do this? I tried to subtask using this code, but I got an error from rake saying task not found. ``` #!/usr/bin/env rake # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require File.expand_path('../config/application', __FILE__) API::Application.load_tasks task :demo => :seed do end task :seed => :db ```

Original source