I’m using a rails 3.1.3 project which has rake (0.9.2.2). I want to do this in a rake task: call it like
rake tale:import_kml /path/to/file.txt
and then inside the rake task, get access to “/path/to/file.txt” as args.filename
I thought i would be able to do this like so (the puts is there for bit of debugging):
namespace :tale do
desc "Expects to get a file or folder name as the first argument, and passes that to Tale.import_kml"
task(:import_kml, [:filename] => :environment) do |t, args|
puts "args = #{args.inspect}"
if File.exists?(args.filename)
Tale.import_kml(filename)
end
end
end
But, i get this:
** Invoke tale:import_kml (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute tale:import_kml
args = {}
rake aborted!
can't convert nil into String
so, filename isn’t making it into args. I can’t work out what i’m doing wrong here…
Try such snippet: