Here is a simple example:
task :mytask, [:word0, :word1] do |t, args|
puts "You typed: '#{args.word0}' and '#{args.word1}'"
end
You run this from the command line thus:
$ rake mytask[hello,world]
You typed: 'hello' and 'world'
Interacting with a Rails app involves adding a dependency of :environment. Add this after the array of arguments like this:
task :mytask, [:word0, :word1] => :environment do |t, args|The syntax looks weird but it works.
puts "You typed: '#{args.word0}' and '#{args.word1}'"
end
1 comment:
Thanks that was driving me crazy - where to put the => :environment
Post a Comment