netwire
netwire

Reputation: 7215

Display Mongoid localized field

I have a Mongoid field that's localized, achieved via:

field :name, localize: true

It has both a en version and a de version. Is there a way I can output both locals on the same View? Something like this in HAML, but displaying en and de versions.

= user.name

Upvotes: 1

Views: 614

Answers (1)

Rostyslav Diachok
Rostyslav Diachok

Reputation: 811

You can get and set all the translations at once by using the corresponding _translations method.

You can do this for each language in config.i18n.available_locales = [:de, :en] :

- I18n.available_locales.each do |language|
  = @user.name_translations[language.to_s]

or just:

= @user.name_translations['en']
= @user.name_translations['de']

It's described there http://mongoid.org/en/mongoid/docs/documents.html#localized_fields

Upvotes: 2

Related Questions