【发布时间】:2018-10-30 06:49:48
【问题描述】:
我想定义一个简单的方法来在通过迁移删除特定表时确认用户输入,如下所示。执行此操作的适当文件在哪里?
def confirm_drop(table)
if table_exists?(table)
puts "Warning: Did not drop table to protect data."
puts "Drop the table? [y]es | [n]o | [c]ancel"
answer = STDIN.gets.chomp
if (answer == "y" or answer == "yes")
drop_table :table
elsif (answer == "c" or answer == "cancel")
raise exception "Canceled Migration"
elsif (answer != "n" or answer == "no")
raise exception "Input was something other than. [y]es | [n]o | [c]ancel"
end
end
end
【问题讨论】:
标签: ruby-on-rails migration dry