Rails 5 and Globalize gem: translation missing
Asked Answered
H

0

6

I have a Rails 5 app in which I use Globalize for localization. I'm currently having an issue where I can't save new objects if they don't have any translations.

My model looks like this:

# Product.rb
translates :description, :fallbacks_for_empty_translations => true
has_many :translations
accepts_nested_attributes_for :translations

# ProductTranslation.rb
belongs_to :product, optional: true

My database schema looks for my product_translations looks like this:

t.integer "product_id", null: false
t.string "locale", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "description"
t.index ["locale"], name: "index_product_translations_on_locale"
t.index ["product_id"], name: "index_product_translations_on_product_id"

When I try to save new products I currently get this error:

Unable to save product with id =  got these validation errors {:"translations.globalized_model"=>["translation missing: sv.activerecord.errors.models.product/translation.attributes.globalized_model.required"]}

Any ideas on what I can do to make it work?

Hulk answered 8/8, 2018 at 20:50 Comment(3)
How do you save new products? Can it be because you don't provide translations on new product instance?Annulation
I'd hazard a guess it's not actually a 'translation' issue: I think it's trying to return a translated error message for you but it can't find the translation for that error. Where is your sv.yml file located and what does it look like?Tenderhearted
Another guess: it should be has_many :product_translations - from your code examples given translations isn't a model.Tenderhearted

© 2022 - 2024 — McMap. All rights reserved.