0
我的Rails应用程序有两个模型如何从文件转储服务器
post.rb
class Post < ActiveRecord::Base
# id :integer(11) not null, primary key
# title :text
# body :text
end
和post_dumps.rb
class PostDump < ActiveRecord::Base
# id :integer(11) not null, primary key
# dupm_file
mount_uploader :dupm_file, DumpUploader # sql file was uploaded
end
如何PostDumpsController创建这样的方法
class PostDumpsController < ApplicationController
def update_posts_from_dump
@dump = PostDump.find(params[:id])
Post.destroy_all
# run from root user in server
mysql -uroot -ppasswrord production_bd < @dump.dupm_file_url
end
end
这看起来像一个疯狂的危险的事情要做。如果你没有别的选择,看看'system'命令。 – tadman
@tadman如果我要为这个话题写一首诗,我会将它命名为“两条反射,作为如何拍摄自己的腿的答案。” – mudasobwa