Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rake task with multiple parameters and model access not working

I am getting the following error running my rake task

rake store_reports["1", "2"]
rake aborted!
Don't know how to build task 'store_reports[1,'

My rake task takes 2 parameters and needs to access models inside it. Here is the task

task :store_reports, [:start_date, :end_date] => :environment do |t, args|
    puts args.start_date
end

I referenced both of there stackoverflow questions, but the first answer did not work, and in the second one the author seems to have solved it but he never posted his answer.

rake aborted! undefined method `map' for :name:Symbol rake task with multiple parameters - I got stuck

Heres some extra info. Where I run rake -T I dont see my rake task there

like image 321
user2158382 Avatar asked Sep 10 '13 23:09

user2158382


People also ask

How to write Rake task?

So I decided to write about it here. If you want to write your own rake task you have 2 ways to do it (I thought so before): Write it from scratch. Copy-paste code from another ready rake task and change code to required.

What is a Rake task?

Rake is a software task management and build automation tool created by Jim Weirich. It allows the user to specify tasks and describe dependencies as well as to group tasks in a namespace. It is similar in to SCons and Make.

How do I run a rake file?

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.


1 Answers

try

rake store_reports["1","2"]

as per How to pass command line arguments to a rake task.

the parser is not liking the space between your parameters

like image 175
Anko Avatar answered Oct 20 '22 00:10

Anko