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?

Anders
  • 2,903
  • 7
  • 58
  • 114
  • How do you save new products? Can it be because you don't provide translations on new product instance? – Nondv Aug 12 '18 at 15:28
  • 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? – Stuart Aug 13 '18 at 08:04
  • 1
    Another guess: it should be `has_many :product_translations` - from your code examples given `translations` isn't a model. – Stuart Aug 13 '18 at 08:12

0 Answers0