Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Mongoid localized field

i have a localized field in both locales en and it. In my administration panel i want to set both translation though two text area in the same page

field :text, :type => String, localize: true

How can i built the forms to edit both values in Rails?

like image 568
Luca Milan Avatar asked Apr 17 '26 14:04

Luca Milan


1 Answers

See the Mongoid localized documentation.

You need to set a hash text_translations that contains 2 keys, en and it. So you can create 2 inputs called text_translations['en'] and text_translations['it'] :

  <% ['en', 'it'].each do |key| %>
  <div class="field">
    <%= f.label key %><br />
    <%= text_field_tag "text_translations[" + key + "]", @model.text_translations[key] %> 
  </div>
<% end %>

In your controller (update and create) you can do :

model.text_translations = params[:text_translations]
like image 50
Aymeric Avatar answered Apr 20 '26 06:04

Aymeric