0

I'm using Globalize 3.1 and globalize-accessors on an old rails 3.2 project, in order to store some translated fields, in 3 languages. I have two models, a Company with many basic details [title, address, lat, lng, image etc], where I translate the 'title' and a Description with two fields [summary and description], where I translate both the 'summary' and 'description'.

I'm using simple_forms to add all translated fields in my admin, in [:en, :de, :it] locales.

Everything stores and updates without any problem, but the 'title_en' from the Company remains the initial, so I cannot change it if I want.

in Company model

translates :title
globalize_accessors locales: [:en, :de, :it], attributes: [:title]

in Controller

permitted = [:title_en, :title_de, :title_it, :address, :lat, :lng, 
{ description_attributes: [ :summary_en, :description_en, :summary_de, :description_de, :summary_it, :description_it ] }, ....

in my View

   <strong>English Translation:</strong>
    <%= f.input :title_en %>
    <%= f.simple_fields_for :description do |p| %>
     <%= p.input :summary_en %>
     <%= p.input :description_en, :as => :text, :input_html => { :rows => 20 } %>
    <% end %>
   <hr>
   <strong>Italian Translation:</strong>
    <%= f.input :title_it %>
    <%= f.simple_fields_for :description do |p| %>
     <%= p.input :summary_it %>
     <%= p.input :description_it, :as => :text %>
    <% end %>
   <hr>

I have double check every possible misspell or error, but the problem remains, no matter if I'm just adding the empty translation to a Company, or I have already filled all translated fields. The 'title_en' remains always the same. All other fields (title_it, title_de, summary_en, description_en, description_it etc) can be updated without any issue.

Do you have any idea? Thank you!

****** Additional Info ******* This is my Update Action

  def update
    expire_fragment(params[:id])
    return update_rates if params[:company][:rates_attributes]
    respond_with @company = Company.update(params[:id], company_params), location: admin_companies_url
  end

def company_params
  permitted = [:title_en, :title_de, :title_it, :address, :lat, :lng, .....
  { description_attributes: [ :summary_en, :description_en,    :summary_de, :description_de, :summary_it, :description_it ] },
  { rates_attributes: [:id, :status, :date, :price] },   :images_attributes,:amenity_ids]
  params.require(:company).permit(*permitted)
end
stefkas
  • 81
  • 1
  • 1
  • 6
  • It seems that there is an open issue with ["Single language field with accepts_nested_attributes_for not stored"](https://github.com/globalize/globalize-accessors/issues/31) but it occurs only when other fields are empty and in nested params. My nested model works fine without any problem. – stefkas Dec 01 '17 at 20:17
  • Can you show your update action and errors if any? – EJAg Dec 01 '17 at 20:17
  • def update return update_rates if params[:company][:rates_attributes] respond_with @company = Company.update(params[:id], company_params) end – stefkas Dec 01 '17 at 20:21
  • def company_params permitted = [:title_en, :title_de, :title_it, :address, :lat, :lng, ..... { description_attributes: [ :summary_en, :description_en, :summary_de, :description_de, :summary_it, :description_it ] }, { rates_attributes: [:id, :status, :date, :price] }, :images_attributes, :amenity_ids] params.require(:company).permit(*permitted) end – stefkas Dec 01 '17 at 20:24
  • Would be more helpful if you could edit your question to include new information rather than using comments. It's difficult to read. – EJAg Dec 01 '17 at 20:26
  • Correct EJ2015. Added in my post. – stefkas Dec 01 '17 at 20:38

1 Answers1

1
   <strong>English Translation:</strong>
<%= f.input :title_it %>

Line 2 = :title_it

Alex Baidan
  • 1,065
  • 7
  • 15
  • Thanks Oleksii! Unfortunately, it was just a misspell here in stackoverflow post, not on real code. In actual code, I have some more :input_html tags, which I simplified here. – stefkas Dec 01 '17 at 20:10
  • did you debug? What values you have on update action in Controller? – Alex Baidan Dec 01 '17 at 20:13
  • Yes, all parameters pass correct. The 'title_en' is the new as well as the other fields. – stefkas Dec 01 '17 at 20:19
  • try to check Company. globalize_locales and Company.globalize_locales_names values before update action (in debugger) – Alex Baidan Dec 01 '17 at 20:25