I'm using rails 3.2.8, globalize3 and batch_translations to translate specific content for an little cms and shop system. I integrated it without problems for one translation on one model. So everthings works fine. I started adding this functionality for my other models and..shhhhh weird things happen.
Status now: I can create new content with translations. Everything ok. But if I try to edit/update the values in the translations tables nothing happen! Maybe there is a wrong parameter path in batch_translations or something...
Here an example for categories!
migration_file
class CreateCategories < ActiveRecord::Migration
def self.up
create_table :categories do |t|
t.timestamps
end
Category.create_translation_table! :category_name => :string, :description => :string
end
def self.down
Category.drop_translation_table!
drop_table :categories
end
end
model:
class Category < ActiveRecord::Base
attr_accessible :category_name, :description
attr_accessible :translations_attributes
translates :category_name, :description
has_many :translations
accepts_nested_attributes_for :translations
class Translation
attr_accessible :locale, :category_name, :description
end
end
this weird class Translation I wrote because I got mass-assignemnt errors for locale, etc...
form:
<div>
<%= form_for @category, html: { :multipart => true } do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<%= build_translation_text_field f, :category_name, :description %>
<%= f.submit (t ".save"), class: "btn btn-large btn-primary" %>
<% end %>
</div>
helper for my translation form:
def build_translation_text_field(f, *atts)
tag = content_tag(:h1, "Test")
I18n.available_locales.each do |l|
f.globalize_fields_for l do |g|
atts.each do |a|
tag += content_tag(:div, content_tag(:h4, t(a)+":"))
tag += (g.text_field a, class: l)
end
end
end
tag
end
categories_controller update method:
def create
@category = Category.new(params[:category])
if @category.save
@categories = Category.all
flash[:success] = t(:category_created)
respond_to do |format|
format.html {render 'index'}
format.js
end
else
flash[:error] = @category.errors.full_messages.each {|msg| p msg}
@categories = Category.all
respond_to do |format|
format.html {render 'new'}
format.js
end
end
end
def update
@category = Category.find(params[:id])
if @category.update_attributes(params[:category])
@categories = Category.all
flash[:success] = t(:category_updated)
respond_to do |format|
format.html {render 'index'}
format.js
end
else
flash[:error] = @category.errors.full_messages.each {|msg| p msg}
@categories = Category.all
respond_to do |format|
format.html {render 'edit'}
format.js
end
end
end
anyone an idea or have an working example with two models whit one or more translated attributes?
My fault:
Update for the model: