English 中文(简体)
如何验证翻译的数据?
原标题:How to validate translated data?

我使用的是“铁路”(3.2.2),globalize3 (0.20)和batch_translations(0.1.2) 我也希望验证由全球化3处理的翻译数据。 例如,......

......载于我的<代码>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

... in my ROOT_RAILS/app/views/articles/_form.htmlerb 档案:

<%= 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 %>

在提交表格时,<代码><<<>/code>和content数值不为I18n. locale。 换言之,为了在数据库中储存对译文的正确信息,如果用户为非缺英文的当地语文提交翻译数据,我谨确认<代码> <<>>> > <> > 代码>和< 代码>content 属性。

www.un.org/spanish/ecosoc 是否可能? 如果是,

注 问题。

问题回答

如果我正确理解你的话,你可以采取一些办法。

(1) 控制器级测试,在测试中,与当地人提交的表格仍然保留到正确的当地化内容表。 这样做的一种方式就是:

    it "persists localized content for the Italian locale" do
       Article.should_receive(:create).with(:locale =>  it , :title =>  title goes here , :content =>  this is content )
       post :create, :locale =>  it , :title =>  title goes here , :content =>  this is content 
    end

这基本上说,该条模式应当收到这些论点所产生的信息。 我并不完全清楚批量——转译文是如何运作的,因此,你要核实,这就是这些参数如何源自这种风格。

At that point, I think you d be adequately testing that the data got persisted to the database correctly. Anything further would be testing that the Globalize gem works, which you want to avoid. Try and test the boundaries.





相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...