我正在使用 Ruby on Rails (3.2.2)、globalize3 (0.2.0) 和batch_translations (0.1.2) ruby-gems。我想验证由 globalize3 处理的翻译数据以及它应该是的。也就是说,例如,如果...
...在我的ROOT_RAILS/app/models/article.rb
文件中,我有:
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
...在我的ROOT_RAILS/app/views/articles/_form.html.erb
文件中,我有:
<%= 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 %>
我想在提交表单时验证数据title
和content
值,而当前I18n.locale
不是I18n.default_locale
. 换句话说,为了在数据库中存储正确的翻译信息,我想在用户提交非默认英语语言的语言环境的翻译数据时验证title
和属性。content
可能吗?如果是这样,怎么做?
注意:我以this question为例。