I am using Ruby on Rails (3.2.2), globalize3 (0.2.0) and batch_translations (0.1.2) ruby-gems. I would like to validate translated data handled by globalize3 as well as it should be. That is, for example, if...
... in my ROOT_RAILS/app/models/article.rb
file I have:
class Article < ActiveRecord::Base
translates :title, :content
# This is needed to make the batch_translations to work.
attr_accessible :translations_attributes
accepts_nested_attributes_for :translations
validates :title,
:presence => true,
:length => ...
validates :content,
:presence => true,
:length => ...
...
end
... in my ROOT_RAILS/app/views/articles/_form.html.erb
file I have:
<%= form_for(@article) do |f| %>
English translation:
<%= f.text_field :title %>
<%= f.text_field :content %>
Italiano translation:
<%= f.globalize_fields_for :it do |g| %>
<%= g.text_field :title %>
<%= f.text_field :content %>
<% end %>
<% end %>
I would like to validate data for title
and content
values when submitting the form and the current I18n.locale
is not the I18n.default_locale
. In other words, in order to store in the database correct information also for translations, I would like to validate title
and content
attributes when an user submit translation data for a locale language that is not the default English language.
Is it possible? If so, how?
Note: I took example from this question.