Many times on a rake task it’s better to have a confirmation before continuing the task. This is especially required before important tasks like a deployment or a database migration in production.

Adding a gets doesn’t work at all. To overcome this, we can add a confirm task which is run before the actual task is run.

The confirm task –

task :confirm do
  STDOUT.puts "Are you sure? (y/n)"
  input = STDIN.gets.chomp.downcase
  raise "Aborting" unless input == 'y'
end

Now, make the actual task run after the confirm task –

task :deploy => :confirm do
  puts "continued task ..."
end

Reference: CoderWall