1

I am using Ruby on Rails 4 and the Globalize gem.

When I submit multiple translations from a form in my application, Globalize creates a new record for each locale in the translation database table, even if the translation for the given locale already exists in that table.

I would like to have one translation per locale so when the form is submitted then a new translation record is created only if it doesn't exist yet, otherwise it should be just updated with the submitting data.

How can I do that?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
user502052
  • 14,803
  • 30
  • 109
  • 188

1 Answers1

0

It's hard to answer this question without more information about the format of data in the form.

Assuming you have all the locales in I18n.available_locales, and you are updating an attribute title, something like this will work (assuming your record is called post):

I18n.available_locales.each do |locale|
  post.translation_for(locale).title ||= ...
end
post.save!

I can provide more specific guidance if you provide more info.

Chris Salzberg
  • 27,099
  • 4
  • 75
  • 82
  • Maybe [this](http://stackoverflow.com/questions/20268557/how-and-where-to-handle-the-updating-process-of-associated-records) can help you to help me... – user502052 Jan 06 '14 at 15:41