2

こんにちは、 http://docs.rhomobile.com/faq#how-to-pre-populate-client-databaseで述べたように、データベースに事前入力しています が、デフォルト コードで DB をリセットすると問題が発生します。

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"
  %>

しかし、私が今抱えている唯一の問題は、テキスト内の一重引用符別名 ' です。それらは、? が付いた三角形としてアプリに表示されます。中のようなものです。何をすべきか?

4

1 に答える 1

1

こちら で説明されているように、パイプ区切りのテキスト ファイルを使用してデータベースをシードできます。

したがって、Property Bag モデル定義を使用しているインスタンスでは、ファイルを呼び出して、object_values.txt必要なソース、プロパティ、および値をロードします。

于 2011-08-18T13:41:40.353 に答える