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?
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]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With