I added a virtual attribute to a record via attribute
like this.
class Question < ApplicationRecord
extend Mobility
attribute :hint
translates :hint, type: :text
end
Works so far. Even the by Mobility added methods like question.hint_fr=
etc. are available. Now I assumed Mobility would on question.save
also create the corresponding Mobility::Backends::ActiveRecord::KeyValue::StringTranslation
record, but it doesn't. Why doesn't it? What am I missing?
Thanks a lot in advance for your help.
Update: I fall into a trap. I had the option column_fallback true
set and then when Mobility.locale
and I18n.default_locale
where the same, for some reason the attributes translation was not saved. If I disable the option column_fallback
then the translation gets saved as expected.
It seems for me that Mobility never saves a translation if Mobility.locale
and I18n.default_locale
are the same. Which caused some headache to me because together with the column_fallback true
option this leads to rather unexpected behaviour. Imagine I18n.default_locale
is :de
and Mobility.locale
too and then you map fallbacks to e.g. {:fr => :de}
which on record attribute access an environment with Mobility.local = :fr
then leads to nil
because the :de
translation actually does not exist.