Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RAILS - Passing parameters to a Rake task [duplicate]

i need some help :( well, i need to pass 1 parameter to a rake task. And I'm not 100% sure how to do this, I've tried a lot of things, but nothing actually works. it's look like this :

 {  task :export, [:arg1]  => :environment do
      puts "Exporting..."
      Importer.export_to_csv([:arg1]).to_i
      puts "done."
    end }

and then 'export_to_csv' method spoused to get the arg when I ran in my terminal : 'rake export 1' or 'rake export [1]' I keep getting the same error-answer: 'rake aborted! NoMethodError: undefined method `id' for nil:NilClass'

which is means - he didn't recognize this input. Thank u guys ahead,

like image 451
miss_M Avatar asked Nov 29 '22 23:11

miss_M


1 Answers

try this, also have a look on following url. 4 Ways to Pass Arguments to a Rake Task

task :export, [:arg1] => :environment do |t, args|
  puts "Exporting..."
  Importer.export_to_csv(args[:arg1].to_i)
  puts "done."
end

and run it using

rake add\[1\]

#OR

rake 'export[1]'
like image 154
Amit Sharma Avatar answered Dec 05 '22 01:12

Amit Sharma