Reputation: 125
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?
Upvotes: 3
Views: 1297
Reputation: 906
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]
Upvotes: 5