Rhomobile で、ローカル ファイルからローカル データベースをシードできることを見てきました。ファイルはテキストファイルである必要があり、フォーマットは次のようになります。
client_id|last_sync_success
67320d31-e42e-4156-af91-5d9bd7175b08|
しかし、csv ファイルからデータをシードする方法はありますか?
以下のようなものを使用できます。
# For seeding question to question table from question.csv file
if MyModel.find(:all).empty?
file_name = File.join(Rho::RhoApplication.get_app_path('public')+'sample.csv')
file = File.new(file_name, "r")
while (line = file.gets)
col = (line.gsub("\n", "")).split(";")
MyModel.create( {"id" => col[0].gsub('"',''), "text" => col[1].gsub('"','')} )
end
end
これがお役に立てば幸いです。