I am able to pass in arguments as follows:

desc "Testing args"
task: :hello, :user, :message do |t, args|
  args.with_defaults(:message => "Thanks for logging on")
  puts "Hello #{args[:user]}. #{:message}"
end

I am also able to load the current environment for a Rails application

desc "Testing environment"
task: :hello => :environment do 
  puts "Hello #{User.first.name}."
end

What I would like to do is be able to have variables and environment

desc "Testing environment and variables"
task: :hello => :environment, :message do |t, args|
  args.with_defaults(:message => "Thanks for logging on")
  puts "Hello #{User.first.name}. #{:message}"
end

But that is not a valid task call. Does anyone know how I can achieve this?

5 Answers
5

Leave a Reply

Your email address will not be published. Required fields are marked *