嗨,我正在预填充数据库,如此处所述 http://docs.rhomobile.com/faq#how-to-pre-populate-client-database 但我有一个问题,当我使用默认代码重置数据库时
def do_reset
Rhom::Rhom.database_full_reset
SyncEngine.dosync
@msg = "Database has been reset."
redirect :action => :index, :query => {:msg => @msg}
end
那么我正在丢失数据。当我进行重置时,如何使预填充的数据库始终被加载。干杯
我想出了这样的解决方案
在视图中 do_reset.erb
<%
Antwort.delete_all()
file_name = File.join(Rho::RhoApplication::get_model_path('app','Settings'), 'antwort.txt')
file = File.new(file_name,"r")
aid=0
file.each_line("\n") do |row|
col = row.split("|")
aid=aid+1
@antwort=Antwort.create(
{"aid" => aid, "qid" => col[0],"antwort"=>col[1],"richtig"=>col[2]}
)
qty=file.lineno
break if file.lineno > 3000
end
Questions.delete_all()
file_name = File.join(Rho::RhoApplication::get_model_path('app','Settings'), 'questions.txt')
file = File.new(file_name)
file.each_line("\n") do |row|
col = row.split("|")
@question=Questions.create(
{"id" => col[0], "question" => col[1],"answered"=>'0',"show"=>'1',"tutorial"=>col[4]}
)
break if file.lineno > 1500
end
file.close
@msg="OK"
%>
但我现在唯一的问题是文本中的单引号又名 ' 。然后它们在应用程序中显示为带有 ? 的三角形。里面就像一个。该怎么办?