0

.txt ファイルからシード データをロードするために使用すると、load_offline_data の問題に直面しています。

私のコードは次のようになります:

> def initialize
>     Rho::RHO.load_all_sources()
>     products = Product.find(:all)
>     Rho::RhoUtils.load_offline_data(['products'], 'db')   end

db/fixtures/products.txt 内

source_name|attrib|object|value
Product|name|1|product 1| Product|order_id|1|1|

Product|name|2|product 2|
Product|order_id|2|2|

次のようなエラーが表示されます:

アプリケーションの初期化に失敗しました: #source_id' for nil:NilClass>;Trace: lib/rho/rhoutils.rb:71:inblock (3 レベル) in load_offline_data'

誰でも私を助けることができます..

前もって感謝します !

4

1 に答える 1

0

なるほど、手動で「rho/rhutils」を要求する必要がありました。

source_id エラーを回避するには、Rhom::Rhom.database_full_reset(true, true) を呼び出す必要がありました。これにより、アプリケーションが初期化されるたびにデータベースがリセットされるため、ツリー テーブルにデータが既に入力されていることを確認するガードを含めました。

require 'rho/rhoapplication'
require 'rho/rhoutils'

class AppApplication < Rho::RhoApplication
  def initialize
    # Tab items are loaded left->right, @tabs[0] is leftmost tab in the tab-bar
    # Super must be called *after* settings @tabs!
    @tabs = nil
    #To remove default toolbar uncomment next line:
    #@@toolbar = nil
    super

    if Tree.find_all.empty?
      Rhom::Rhom.database_full_reset(true, true)
      Rho::RhoUtils.load_offline_data(['object_values'], '')
    else
      puts "*"*80
      puts "ALL GOOD"*5
      puts "*"*80
    end

    # Uncomment to set sync notification callback to /app/Settings/sync_notify.
    # SyncEngine::set_objectnotify_url("/app/Settings/sync_notify")
    # SyncEngine.set_notification(-1, "/app/Settings/sync_notify", '')
  end
end
于 2012-06-02T19:17:16.433 に答える