@@ -3,7 +3,7 @@ Ruby on Rails 4.2 发布记
3
3
4
4
Rails 4.2 精华摘要:
5
5
6
- 本篇仅记录主要的变化。要了解关于已修复的 Bug、功能变更等 ,请参考 [ Rails GitHub 主页] ( https://github.com/rails/rails ) 上各个 Gem 的 CHANGELOG 或是 [ Rails 的提交历史] ( https://github.com/rails/rails/commits/master ) 。
6
+ 本篇仅记录主要的变化。要了解关于已修复的 Bug、特性变更等 ,请参考 [ Rails GitHub 主页] ( https://github.com/rails/rails ) 上各个 Gem 的 CHANGELOG 或是 [ Rails 的提交历史] ( https://github.com/rails/rails/commits/master ) 。
7
7
8
8
--------------------------------------------------------------------------------
9
9
@@ -12,8 +12,8 @@ Rails 4.2 精华摘要:
12
12
13
13
如果您正试着升级现有的应用程序,最好有广的测试覆盖度。首先应先升级至 4.1,确保应用程序仍正常工作,接着再升上 4.2。升级需要注意的事项在 [ Ruby on Rails 升级指南] ( upgrading_ruby_on_rails.html#upgrading-from-rails-4-1-to-rails-4-2 ) 可以找到。
14
14
15
- 重要新功能
16
- --------------
15
+ 重要新特性
16
+ ---------
17
17
18
18
### 外键支援
19
19
@@ -42,9 +42,14 @@ Railties
42
42
43
43
### 移除
44
44
45
- * 移除了 ` rails application ` 命令。
45
+ * 移除 ` rails application ` 命令。
46
46
([ Pull Request] ( https://github.com/rails/rails/pull/11616 ) )
47
47
48
+ ### 弃用
49
+
50
+ * 弃用 ` Rails::Rack::LogTailer ` ,没有替代方案。
51
+ ([ Commit] ( https://github.com/rails/rails/commit/84a13e019e93efaa8994b3f8303d635a7702dbce ) )
52
+
48
53
### 值得一提的变化
49
54
50
55
* 导入 ` bin/setup ` 脚本来启动应用程序。
@@ -53,7 +58,7 @@ Railties
53
58
* ` config.assets.digest ` 在开发模式的缺省值改为 ` true ` 。
54
59
([ Pull Request] ( https://github.com/rails/rails/pull/15155 ) )
55
60
56
- * 导入给 ` rake notes ` 注册新扩展功能的 API。
61
+ * 导入给 ` rake notes ` 注册新扩展特性的 API。
57
62
([ Pull Request] ( https://github.com/rails/rails/pull/14379 ) )
58
63
59
64
* 导入 ` Rails.gem_version ` 作为返回 ` Gem::Version.new(Rails.version) ` 的便捷方法。
@@ -66,7 +71,7 @@ Action Pack
66
71
67
72
### 弃用
68
73
69
- * 弃用路由的 ` :to ` 选项里,` :to ` 可以指向符号或不含井号的字串这两个功能 。
74
+ * 弃用路由的 ` :to ` 选项里,` :to ` 可以指向符号或不含井号的字串这两个特性 。
70
75
71
76
``` ruby
72
77
get ' /posts' , to: MyRackApp => (No change necessary)
@@ -79,6 +84,13 @@ Action Pack
79
84
80
85
# ## 值得一提的变化
81
86
87
+ * ` render nothing: true` 或渲染 ` nil` 主体不再给响应加一个空白。
88
+ ([Pull Request ](https: // github.com/ rails/ rails/ pull/ 14883 ))
89
+
90
+ * 导入 ` always_permitted_parameters` 选项,用来设定全局允许赋值的参数。默认值是
91
+ ` ['controller', 'action']` 。
92
+ ([Pull Request ](https: // github.com/ rails/ rails/ pull/ 15933 ))
93
+
82
94
* ` *_filter` 方法已经从文档中移除,已经不鼓励使用。偏好使用 ` *_action` 方法:
83
95
84
96
` ` ` ruby
@@ -105,7 +117,7 @@ Action Pack
105
117
* 从 RFC - 4791 新增 HTTP 方法 ` MKCALENDAR` 。
106
118
([Pull Request ](https: // github.com/ rails/ rails/ pull/ 15121 ))
107
119
108
- * ` *_fragment.action_controller` 通知消息的 Payload 现在包含 Controller 与动作名称 。
120
+ * ` *_fragment.action_controller` 通知消息的 Payload 现在包含控制器与动作名称 。
109
121
([Pull Request ](https: // github.com/ rails/ rails/ pull/ 14137 ))
110
122
111
123
* 传入 URL 辅助方法的片段现在会自动 Escaped 。
@@ -118,7 +130,7 @@ Action Pack
118
130
([Pull Request ](https: // github.com/ rails/ rails/ pull/ 14280 ))
119
131
120
132
Action View
121
- -------------
133
+ -----------
122
134
123
135
请参考 [CHANGELOG ][action- view] 来了解更多细节。
124
136
@@ -134,36 +146,49 @@ Action View
134
146
135
147
# ## 值得一提的变化
136
148
149
+ * 表单帮助方法针对隐藏栏位不再加上含有行内样式的 ` <div>` 。
150
+ ([Pull Request ](https: // github.com/ rails/ rails/ pull/ 14738 ))
151
+
137
152
Action Mailer
138
153
-------------
139
154
140
155
请参考 [CHANGELOG ][action- mailer] 来了解更多细节。
141
156
142
157
# ## 值得一提的变化
143
158
159
+ * 添加 ` show_previews` 设定选项,用来在开发环境以外启用 Mailer 预览。
160
+ ([Pull Request ](https: // github.com/ rails/ rails/ pull/ 15970 ))
161
+
144
162
Active Record
145
163
-------------
146
164
147
165
请参考 [CHANGELOG ][active- record] 来了解更多细节。
148
166
149
167
# ## 移除
150
168
169
+ * 移除 ` cache_attributes` 以及其它相关的方法,所有的属性现在都会缓存了。
170
+ ([Pull Request ](https: // github.com/ rails/ rails/ pull/ 15429 ))
171
+
151
172
* 移除已弃用的方法 ` ActiveRecord::Base.quoted_locking_column` .
152
173
([Pull Request ](https: // github.com/ rails/ rails/ pull/ 15612 ))
153
174
154
175
* 移除已弃用的方法 ` ActiveRecord::Migrator.proper_table_name` 。
155
176
请改用 ` ActiveRecord::Migration` 的实例方法:` proper_table_name` 。
156
177
([Pull Request ](https: // github.com/ rails/ rails/ pull/ 15512 ))
157
178
158
- * 移除 ` cache_attributes` 以及其它相关的方法,所有的属性现在都会快取了。
159
- ([Pull Request ](https: // github.com/ rails/ rails/ pull/ 15429 ))
160
-
161
179
* 移除了未使用的 ` :timestamp` 类型。把所有 ` timestamp` 类型都改为 ` :datetime` 的别名。
162
180
修正在 ` ActiveRecord` 之外,栏位类型不一致的问题,譬如 XML 序列化。
163
181
([Pull Request ](https: // github.com/ rails/ rails/ pull/ 15184 ))
164
182
165
183
# ## 弃用
166
184
185
+ * 弃用对 ` has_many :through` 自动侦测 counter cache 的支持。要自己对 ` has_many` 与
186
+ ` belongs_to` 关联,给 ` through` 的纪录手动设定。
187
+ ([Pull Request ](https: // github.com/ rails/ rails/ pull/ 15754 ))
188
+
189
+ * 弃用 ` serialized_attributes` without replacement.
190
+ ([Pull Request ](https: // github.com/ rails/ rails/ pull/ 15704 ))
191
+
167
192
* 弃用了当栏位不存在时,还会从 ` column_for_attribute` 返回 ` nil` 的情况。
168
193
Rails 5.0 将会返回 Null Object 。
169
194
([Pull Request ](https: // github.com/ rails/ rails/ pull/ 15878 ))
@@ -184,12 +209,27 @@ Active Record
184
209
185
210
([Commit ](https: // github.com/ rails/ rails/ commit/ 91949e48cf41af9f3e4ffba3e5eecf9b0a08bfc3))
186
211
187
- * 弃用对 ` has_many :through` 自动侦测 counter cache 的支持。要自己对 ` has_many` 与
188
- ` belongs_to` 关联,给 ` through` 的纪录手动设定。
189
- ([Pull Request ](https: // github.com/ rails/ rails/ pull/ 15754 ))
190
-
191
212
# ## 值得一提的变化
192
213
214
+ * 单数关联增加 ` :required` 选项,用来定义关联的存在性验证。
215
+ ([Pull Request ](https: // github.com/ rails/ rails/ pull/ 16056 ))
216
+
217
+ * 导入 ` ActiveRecord::Base#validate!` ,若记录不合法时会抛出 ` RecordInvalid` 。
218
+ ([Pull Request ](https: // github.com/ rails/ rails/ pull/ 8639 ))
219
+
220
+ * ` ActiveRecord::Base#reload` 现在的行为同 ` m = Model.find(m.id)` ,代表不再给自定的
221
+ ` select` 保存额外的属性。
222
+ ([Pull Request ](https: // github.com/ rails/ rails/ pull/ 15866 ))
223
+
224
+ * 导入 ` bin/rake db:purge` 任务,用来清空当前环境的数据库。
225
+ ([Commit ](https: // github.com/ rails/ rails/ commit/ e2f232aba15937a4b9d14bd91e0392c6d55be58d))
226
+
227
+ * ` ActiveRecord::Dirty` 现在会侦测可变数值的变化。序列化过的属性只在有变更时才会保存。
228
+ 修复了像是 PostgreSQL 不会侦测到字串或 JSON 栏位改变的问题。
229
+ (Pull Requests [1 ](https: // github.com/ rails/ rails/ pull/ 15674 ),
230
+ [2 ](https: // github.com/ rails/ rails/ pull/ 15786 ),
231
+ [3 ](https: // github.com/ rails/ rails/ pull/ 15788 ))
232
+
193
233
* 新增 ` ActiveRecord::Base` 对象的 ` #pretty_print` 方法。
194
234
([Pull Request ](https: // github.com/ rails/ rails/ pull/ 15172 ))
195
235
@@ -216,9 +256,6 @@ Active Record
216
256
* 新增 PostgreSQL 适配器的使用自建的范围类型支持。
217
257
([Commit ](https: // github.com/ rails/ rails/ commit/ 4cb47167e747e8f9dc12b0ddaf82bdb68c03e032))
218
258
219
- * 单数关联增加 ` :required` 选项,用来定义关联的存在性验证。
220
- ([Pull Request ](https: // github.com/ rails/ rails/ pull/ 16056 ))
221
-
222
259
Active Model
223
260
------------
224
261
@@ -231,6 +268,12 @@ Active Model
231
268
232
269
# ## 值得一提的变化
233
270
271
+ * ` ActiveModel::Dirty` 导入 ` undo_changes` 方法,用来恢复变更的属性到先前的数值。
272
+ ([Pull Request ](https: // github.com/ rails/ rails/ pull/ 14861 ))
273
+
274
+ * 若启用验证,` has_secure_password` 现在会检查密码是否少于 72 个字符。
275
+ ([Pull Request ](https: // github.com/ rails/ rails/ pull/ 15708 ))
276
+
234
277
* 引入 ` #validate` 作为 ` #valid?` 的别名。
235
278
([Pull Request ](https: // github.com/ rails/ rails/ pull/ 14456 ))
236
279
@@ -252,25 +295,22 @@ Active Support
252
295
* 弃用 ` Class#superclass_delegating_accessor` ,请改用 ` Class#class_attribute` 。
253
296
([Pull Request ](https: // github.com/ rails/ rails/ pull/ 14271 ))
254
297
255
- * 弃用 ` ActiveSupport::SafeBuffer#prepend!` 请改用 ` ActiveSupport::SafeBuffer#prepend` (两者功能相同 )。
298
+ * 弃用 ` ActiveSupport::SafeBuffer#prepend!` 请改用 ` ActiveSupport::SafeBuffer#prepend` (两者特性相同 )。
256
299
([Pull Request ](https: // github.com/ rails/ rails/ pull/ 14529 ))
257
300
258
301
# ## 值得一提的变化
259
302
303
+ * 新增 ` Hash#transform_values` 与 ` Hash#transform_values!` 方法,来简化 Hash
304
+ 值需要更新、但键保留不变这样的常见模式。
305
+ ([Pull Request ](https: // github.com/ rails/ rails/ pull/ 15819 ))
306
+
260
307
* ` humanize` 现在会去掉前面的底线。
261
308
([Commit ](https: // github.com/ rails/ rails/ commit/ daaa21bc7d20f2e4ff451637423a25ff2d5e75c7))
262
309
263
- * 新增 ` SecureRandom::uuid_v3` 和 ` SecureRandom::uuid_v5` 方法。
264
- ([Pull Request ](https: // github.com/ rails/ rails/ pull/ 12016 ))
265
-
266
310
* 导入 ` Concern#class_methods` 来取代 ` module ClassMethods` 以及 ` Kernel#concern` ,
267
311
来避免使用 ` module Foo; extend ActiveSupport::Concern; end` 这样的样板。
268
312
([Commit ](https: // github.com/ rails/ rails/ commit/ b16c36e688970df2f96f793a759365b248b582ad))
269
313
270
- * 新增 ` Hash#transform_values` 与 ` Hash#transform_values!` 方法,来简化 Hash
271
- 值需要更新、但键保留不变这样的常见模式。
272
- ([Pull Request ](https: // github.com/ rails/ rails/ pull/ 15819 ))
273
-
274
314
致谢
275
315
----
276
316
0 commit comments