Liban
Liban

Reputation: 31

Globalize3-- Save translation to the database

Hey everyone I'm newbie and would love to get some help with saving locale translation to database.

I have this form

= form_for @restaurant do |f|
  = f.fields_for :en_info do |restaurant_en|
    %h4 English Information
    = restaurant_en.label :title
    = restaurant_en.text_field :title
    = restaurant_en.label :description
    = restaurant_en.text_area :description
  = f.fields_for :ar_info do |restaurant_ar|
    %h4 Arabic Information
    = restaurant_ar.label :title
    = restaurant_ar.text_field :title
    = restaurant_ar.label :description
    = restaurant_ar.text_area :description
    = f.submit

And before adding the Arabic form fields there I was able to save the model to the database using this create method in my controller

 def create
    @restaurant = Restaurant.create params[:restaurant][:en_info]
 end

But how can I save the Arabic translation from the form to database?

Upvotes: 3

Views: 410

Answers (1)

Leftis
Leftis

Reputation: 119

Try using globalize3_helpers gem.

= form_for @restaurant do |f|

  - f.globalize_fields_for_locale :en do |l|
    = l.input :title
    = l.input :description, as: :text

  - f.globalize_fields_for_locale :ar do |l|
    = l.input :title
    = l.input :description, as: :text

Upvotes: 0

Related Questions