Skip to content

Instantly share code, notes, and snippets.

@tacitphoenix
Created November 22, 2019 15:11
Show Gist options
  • Save tacitphoenix/b6ec73218f4fe568c014c4cb97a29dd6 to your computer and use it in GitHub Desktop.
Save tacitphoenix/b6ec73218f4fe568c014c4cb97a29dd6 to your computer and use it in GitHub Desktop.
Pass arguments to rake tasks in rails
namespace :rails_rakes do
desc "say hi"
task :hi => :environment do
puts "Hi"
end
desc "say hi with arg"
task :hi_with_arg, [:name] => :environment do |t, args|
puts "Hi #{args[:name]}"
end
desc "say hi with args"
task :hi_with_args, [:name, :age] => :environment do |t, args|
puts "Hi #{args[:name]} you are #{args[:age]}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment