Rails世界:Rails第四版翻译思考(七)
由Gudao Luo在2012-03-20 at 05:08发表的
- 关于词汇fixture翻译
- fixture 静态测试,静态数据,样本测试,样本数据
- test fixture 静态测试,样本测试
- fixture data 静态数据,样本数据
- 参考资料一: Wiki:“http://en.wikipedia.org/wiki/Fixture” 中,相关的条目是:
A fixture can refer to:
Test fixture, used to control and automate testing
某些词典翻译成”夹具“,估计是生产车间里用来夹住待测试的产品进行检测的工具或操作台。
- 参考资料二:Rails Wiki:“http://ar.rubyonrails.org/classes/Fixtures.html” 中,对fixture有一些解释:
Fixtures are a way of organizing data that you want to test against; in short, sample data.
加上原文:
Test Fixtures
In the world of testing, a fixture is an environment in which you can run a test. If you’re testing a circuit board, for example, you might mount it in a test fixture that provides it with the power and inputs needed to drive the function to be tested.
In the world of Rails, a test fixture is simply a specification of the initial contents of a model (or models) under test. If, for example, we want to ensure that our products table starts off with known data at the start of every unit test, we can specify those contents in a fixture, and Rails will take care of the rest.
You specify fixture data in files in the test/fixtures directory. These files contain test data in either comma-separated value (CSV) or Y A M L format. For our tests, we’ll use Y A M L , the preferred format. Each fixture file contains the data for a single model. The name of the fixture file is significant; the base name of the file must match the name of a database table. Because we need some data
我以为:这些描述中,都有测试的意思,都有能“自动”完成部分功能的含义,但是基本上需要人为干预测试数据。
在第七章中有完整并具体的定义,原文为:
In the world of testing, a fixture is an environment in which you can run a test.
Fixtures就是一种软件测试环境!要是单单说“软件测试环境”过于笼统,这是一种以样本数据为特点的软件测试方法。
Rails世界:Rails第四版翻译思考(六)
由Gudao Luo在2012-03-18 at 00:31发表的
- 英文:
- If we pass multiple parameters to a where call, Rails treats the first parameter as a template for the SQL to generate. Within this SQL, we can embed placeholders, which will be replaced at runtime by the values in the rest of the array.
- 中文技术说明一:
可以将一个参数传递到调用函数where。在这参数是数组(Array类)情况下,Rails使用该数组的第一个元素作为生成SQL语句模板。在这SQL语句中,可以嵌入占位符,而在实时运行时这些占位符是由该数组的其它元素来代替。
Order.where([“name = ? and pay_type = ‘po’”, name])
- 中文技术说明二:
可以将多个参数传递到调用函数where。在第一个参数是字符串(String类)情况下,那么Rails使用第一个参数作为生成SQL语句的模板。在这SQL语句中,可以嵌入占位符,在实时运行时这些占位符将由第二个参数(数组)来代替。
Order.where(“name = ? and pay_type = ?”, [name, pay_type])
- 参考资料: http://goo.gl/PUHGp http://goo.gl/szPRn
- 1)the first parameter使用不妥。a)因为第一个参数的第一个元素作为“a template for the SQL”。b)第二个参数是什么?c)只有在这个实例中可以这样说明这个参数使用方法。
- 2)“If we pass multiple parameters to a where call,”,这是一种通用说法,而这一段下面的代码仅仅是只有一个参数的实例。
- 3)要是不看代码,这一段最后的“array”使人感到很突然。
Rails世界:Rails第四版翻译思考(五)
由Gudao Luo在2011-08-04 at 17:34发表的
- 英文:
- Default scopes apply to all queries that start with this model.
- We ask our customer whether she had a preference regarding the order things should be listed in, and we jointly decided to see what happened if we displayed the products in alphabetical order. We do this by adding a default_scope call to the Product model. Default scopes apply to all queries that start with this model.
- 中文:
- 这种默认的scope方法/函数适用于所有该模型的查询。
- 道喜评论
- 看来必须承认:这句话原作者说明不够透出。
- 书上代码default_scope是一个方法/函数,这是有特殊作用的方法/函数,其作用源代码是这样说明的:http://tinyurl.com/6zdewb3
- You can define a scope that applies to all finders using ActiveRecord::Base.default_scope.(这个方法/函数可以作用/适用于所有的查询。)
- 这句话使用default scopes,这说明还有不是默认(default)的scope方法/函数,请看API说明: http://tinyurl.com/366bkjo
- 这种默认方法/函数可以在一个模型里存在多个。所以原文使用复数。请看下面代码。
- function或者method,在软件科学中,我以为,它们是一个概念。但是,就是我写自己东西,也会使用方法或者函数。必须提醒开始接触Rails框架的朋友:在Ruby语言中,对象或者类的属性本身就是方法/函数。我以为,没有必要太多抓住“概念”,而是要理解“概念”,更重要的是:自己真正明白”概念“。
- 这里的Default scopes肯定是指:default_scope 方法/函数。我以为,scopes不应该翻译为“范围限定,范围设定,作用范围”等中文含义。
- 读者是否会联想到,”默认的scope(方法/函数)就是default_scope 方法/函数“?所以利用上下文关系,翻译为“所有这类函数”或者“所有这类方法”,是否更为妥当?
Rails世界:Rails第四版翻译思考(四)
由Gudao Luo在2011-07-26 at 16:31发表的
- 原文
- But Isn’t SQL Dirty?
- It was built on the notion that SQL is neither dirty nor bad, just verbose in the trivial cases.
- 翻译
- SQL语句是灰色的吗?
- 它(Active Record)当时是以这一概念建立起来的,即SQL语言既不是灰色的也不是有缺陷的,只是很简单的SQL查询有点累赘。
道喜评论:
先理解一下,什么是“灰色收入”?存在似乎还有一定的合理性和现实性的收入。从真正意义上说,这种收入是不合理甚至是不合法的。
当然在计算机科学中,灰色(Dirty)既不是说“合理”也不是“合法”的问题,而是通过一种"不寻常"的方法达到处理数据的目的。
例如,类对象的内存地址是确定的。要是修改了该对象属性内容。参见: What’s New in Edge Rails: Dirty Objects 。该对象的内容被修改了,但其内存地址还是保持不变。在早期的Rails版本中,进行这样的修改是无法知晓的,该对象可称之为灰色对象(Dirty Objects)。
修改类对象的属性肯定是可以的。但是问题是在Rails早期版本中,不知道曾经修改了该对象。之后的Rails版本,就可以知道是否修改了该对象。这样就有了一个认知修改的方法。这是一个从灰色走向白色的过程。
Rails世界:Rails第四版翻译思考(三)
由Gudao Luo在2011-07-19 at 11:36发表的
- 原文
- If we pass multiple parameters to a where call, Rails treats the first parameter as a template for the SQL to generate. Within this SQL, we can embed placeholders, which will be replaced at runtime by the values in the rest of the array.
- 参考资料: http://goo.gl/PUHGp http://goo.gl/szPRn
- “the first parameter”使用不妥。a)因为第一个参数的第一个元素作为“a template for the SQL”。b)第二个参数是什么?c)只有在这个实例中可以这样说明这个参数使用方法。
- “If we pass multiple parameters to a where call,”,这是一种通用说法,而这一段下面的代码仅仅是只有一个参数的实例。
- 要是不看代码,这一段最后的“array”使人感到很突然。
- 中文翻译
- 我们可以将一个参数传递到调用函数where。在这参数是数组(Array类)情况下,Rails把该数组的第一个元素作为生成SQL语句模板使用。在这SQL语句中,可以嵌入占位符,而在实时运行时这些占位符是由该数组的其它元素来代替。
- Order.where([“name = ? and pay_type = ‘po’”, name])
- 我们可以将多个参数传递到调用函数where。在第一个参数是字符串(String类)情况下,那么Rails把该第一个参数作为生成SQL语句模板使用。在这SQL语句中,可以嵌入占位符,在实时运行时这些占位符将由第二个参数(数组)来代替。
- Order.where(“name = ? and pay_type = ‘po’”, name)
Rails世界:阅读Rails第四版原版思考(二)
由Gudao Luo在2011-06-29 at 19:20发表的
Rails世界:阅读Rails第四版原版思考(一)
由Gudao Luo在2011-06-28 at 23:19发表的

- 英文原文Page268
Inside the code of the model, we can use the read_attribute and write_attribute private methods. These take the attribute name as a string parameter.
- 网络中文翻译(一)
最后,在model本身的代码内部,你可使用read_attribute()和write_attribute()私有方法。这些接受做为字符串参数的属性的名字。
- 网络中文翻译(二)
最后,也可以使用Model自己的私有方法read_attribute和write_attribute,这两个方法使用属性名作为参数。
- 中文第三版翻译Page238
最后,在模型内部的代码中,我们可以使用read_attribute()和write_attribute()这两个私有方法,参数都是字符串形式的属性名称。
Google世界:网络翻译点滴(视频)
由Gudao Luo在2011-06-26 at 19:54发表的
- 说明Google翻译系统
- 过去一个句子可以让我们得到启示;
- 现在看到单词或者词组也能够让我们得到启发;
- 你可以指导它翻译,如Active Record,第一次会翻译成中文,你把中文更为英文,第二次它就不翻译了。
- 每一个人都在完善这个系统。
- 要是可以拉动单词,自由组合就更好了。
- 要是能够提供自己翻译的个性化链接,就更好了。这样可以发给其他人了。



