2

Ryan Bates railscasts に見られるように Globalize 3 gem を使用していますが、すべて正常に動作します。ただし、データをシードする方法を知る必要があります。現在、次のスキーマでmonthly_post_translationsというテーブルを作成しました

schema.rb

create_table "monthly_post_translations", :force => true do |t|
  t.integer  "monthly_post_id"
  t.string   "locale"
  t.text     "body"
  t.datetime "created_at"
  t.datetime "updated_at"
end

このテーブルにシード データを追加する必要がありますが、操作するモデルがありません。どうすればよいですか?

これが機能していない私の電流の種です。

種.rb

# Monthly Posts
  MonthlyPost.delete_all

 monthlypost = MonthlyPost.create(:body => "Monthly Post Text")


#Monthly Posts Spanish Translation
monthlytranslation = MonthlyPostTranslation.create(:body => "Spanish Translation of monthly post text",
      :monthly_post_id => monthlypost.id,
      :locale => "es" )

しかし、monthly_post_translation テーブルには操作できるモデルがないため、エラーが発生します。

uninitialized constant MonthlyPostTranslation

このシードデータを適切に追加する方法について何か考えはありますか?

4

1 に答える 1

4

ドキュメントから入力 translates :<attribute_name_here>すると、 という名前の生成されたモデルが得られMonthlyPost::Translationます。したがって、答えは次のようになります: インスタンス コレクションを使用して、エンティティのすべての翻訳を作成または一覧表示します。

monthlypost = MonthlyPost.create(:body => "Monthly Post Text")


#Monthly Posts Spanish Translation
monthlytranslation = monthlypost.translations.create(:body => "Spanish Translation of monthly post text",
      :locale => "es" )
于 2012-04-08T21:08:54.910 に答える