Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: rake task with arguments not working

Here is my rake task

namespace :users do
  task :change_role, [:role] => :environment do |t, args|
    puts args.role
  end
end

I am calling it like this:

rake users:change_role["role"] but I am getting this error no matches found: users:change_role["role"]

like image 753
dennismonsewicz Avatar asked Jul 03 '14 15:07

dennismonsewicz


People also ask

How do I run a rake task in Ruby on Rails?

Go to Websites & Domains and click Ruby. After gems installation you can try to run a Rake task by clicking Run rake task. In the opened dialog, you can provide some parameters and click OK - this will be equivalent to running the rake utility with the specified parameters in the command line.

How do I see all rake tasks?

You can get a list of Rake tasks available to you, which will often depend on your current directory, by typing rake --tasks . Each task has a description, and should help you find the thing you need.

Where do I put rake tasks?

rake extension and are placed in Rails. root/lib/tasks . You can create these custom rake tasks with the bin/rails generate task command. If your need to interact with your application models, perform database queries and so on, your task should depend on the environment task, which will load your application code.


1 Answers

You need to escape the square brackets when using them in some shells like zsh:

rake users:change_role\["role"\]
like image 78
infused Avatar answered Oct 07 '22 06:10

infused