17

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

Community
  • 1
  • 1
user2158382
  • 4,430
  • 12
  • 55
  • 97
  • where do you store this task? – BvuRVKyUVlViVIc7 Sep 10 '13 at 23:06
  • the task is in lib/task – user2158382 Sep 10 '13 at 23:17
  • I dont understand why my answer was deleted. The question was that rails couldnt build the task. If the file would be somewhere except lib/tasks and doesn't have a .rake ending, the message would be the same. So i think my answer made sense, maybe not for this case, but in general. Unfortunately I cant undelete or comment my answer, so i post it here. – BvuRVKyUVlViVIc7 Sep 11 '13 at 00:25

1 Answers1

26

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

Community
  • 1
  • 1
Anko
  • 1,292
  • 10
  • 19
  • I know this is an old post but any idea why the rake task wasnot appearing in the list? I am having the same error – Nawshine Aug 13 '14 at 07:04
  • 1
    @Brett - It's not that the parsing is stupid, it's just how shells work. If you put in a space, then ruby sees it as to separate arguments. You could put quotes around the whole thing to make it look like one argument, which would work fine :) Just realise that it's your shell doing something to your input before ruby gets it. – Anko Nov 12 '16 at 02:24
  • FYI, you _shouldn't_ need to put quotes around the individual arguments. In my stock macOS terminal I was able to run `rake store_reports[1,2]` just fine. – Joshua Pinter May 07 '18 at 23:26