I am using the Globalize 3 gem as seen in Ryan Bates railscasts, and everything works fine. I need to know how to seed the data though. Currently, I created a table called monthly_post_translations with the following schema
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
I need to add seed data to this table, but it doesn't have a model to interact with, so how do I do it?
Here is my currents seeds.rb that isn't working
seeds.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" )
But the monthly_post_translation table doesn't have a model that I can interact with, so I get the error
uninitialized constant MonthlyPostTranslation
Any thoughts on how I can add this seed data properly?
As from documentation by typing translates :<attribute_name_here>
you get generated model named MonthlyPost::Translation
. So the answer will be: use instance collection to create or list all translations for entity:
monthlypost = MonthlyPost.create(:body => "Monthly Post Text")
#Monthly Posts Spanish Translation
monthlytranslation = monthlypost.translations.create(:body => "Spanish Translation of monthly post text",
:locale => "es" )