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