-
Notifications
You must be signed in to change notification settings - Fork 0
/
4_0_release_notes.html
556 lines (525 loc) · 38.1 KB
/
4_0_release_notes.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
<!DOCTYPE html>
<html lang="zh-TW">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Ruby on Rails 4.0 Release Notes — Ruby on Rails 指南</title>
<meta name="description" content="Ruby on Rails 指南:系統學習 Rails(Rails 4.2 版本)" >
<meta name="keywords" content="Ruby on Rails Guides 指南 中文 學習 免費 網路 Web 開發" >
<meta name="author" content="http://git.io/G_R1sA">
<meta property="fb:admins" content="1340181291">
<meta property="og:title" content="Ruby on Rails 4.0 Release Notes — Ruby on Rails 指南" >
<meta property="og:site_name" content="Ruby on Rails 指南">
<meta property="og:image" content="http://rails.ruby.tw/images/rails_guides_cover.jpg">
<meta property="og:url" content="http://rails.ruby.tw/">
<meta property="og:type" content="article">
<meta property="og:description" content="Ruby on Rails 指南:系統學習 Rails(Rails 4.2 版本)">
<link rel="stylesheet" href="stylesheets/application.css">
<link href="http://fonts.googleapis.com/css?family=Noto+Sans:400,700|Noto+Serif:700|Source+Code+Pro" rel="stylesheet">
<link href="images/favicon.ico" rel="shortcut icon" type="image/x-icon">
</head>
<body class="guide">
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/zh-TW/sdk.js#xfbml=1&appId=837401439623727&version=v2.0";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<script type="text/javascript">
window.twttr=(function(d,s,id){var t,js,fjs=d.getElementsByTagName(s)[0];if(d.getElementById(id)){return}js=d.createElement(s);js.id=id;js.src="https://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);return window.twttr||(t={_e:[],ready:function(f){t._e.push(f)}})}(document,"script","twitter-wjs"));
</script>
<div id="topNav">
<div class="wrapper">
<strong class="more-info-label">更多內容 <a href="http://rubyonrails.org/">rubyonrails.org:</a></strong>
<span class="red-button more-info-button">
更多內容
</span>
<ul class="more-info-links s-hidden">
<li class="more-info"><a href="http://rubyonrails.org/">綜覽</a></li>
<li class="more-info"><a href="http://rubyonrails.org/download">下載</a></li>
<li class="more-info"><a href="http://rubyonrails.org/deploy">部署</a></li>
<li class="more-info"><a href="https://github.com/rails/rails">原始碼</a></li>
<li class="more-info"><a href="http://rubyonrails.org/screencasts">影片</a></li>
<li class="more-info"><a href="http://rubyonrails.org/documentation">文件</a></li>
<li class="more-info"><a href="http://rubyonrails.org/community">社群</a></li>
<li class="more-info"><a href="http://weblog.rubyonrails.org/">Blog</a></li>
</ul>
</div>
</div>
<div id="header">
<div class="wrapper clearfix">
<h1><a href="index.html" title="回首頁">Guides.rubyonrails.org</a></h1>
<ul class="nav">
<li><a class="nav-item" href="index.html">首頁</a></li>
<li class="guides-index guides-index-large">
<a href="index.html" id="guidesMenu" class="guides-index-item nav-item">指南目錄</a>
<div id="guides" class="clearfix" style="display: none;">
<hr>
<dl class="L">
<dt>起步走</dt>
<dd><a href="getting_started.html">Rails 起步走</a></dd>
<dt>Models</dt>
<dd><a href="active_record_basics.html">Active Record 基礎</a></dd>
<dd><a href="active_record_migrations.html">Active Record 遷移</a></dd>
<dd><a href="active_record_validations.html">Active Record 驗證</a></dd>
<dd><a href="active_record_callbacks.html">Active Record 回呼</a></dd>
<dd><a href="association_basics.html">Active Record 關聯</a></dd>
<dd><a href="active_record_querying.html">Active Record 查詢</a></dd>
<dt>Views</dt>
<dd><a href="layouts_and_rendering.html">Rails 算繪與版型</a></dd>
<dd><a href="form_helpers.html">Action View 表單輔助方法</a></dd>
<dt>Controllers</dt>
<dd><a href="action_controller_overview.html">Action Controller 綜覽</a></dd>
<dd><a href="routing.html">Rails 路由:深入淺出</a></dd>
</dl>
<dl class="R">
<dt>深入了解</dt>
<dd><a href="active_support_core_extensions.html">Active Support 核心擴展</a></dd>
<dd><a href="i18n.html">Rails 國際化 API</a></dd>
<dd><a href="action_mailer_basics.html">Action Mailer 基礎</a></dd>
<dd><a href="active_job_basics.html">Active Job 基礎</a></dd>
<dd><a href="security.html">Rails 安全指南</a></dd>
<dd><a href="debugging_rails_applications.html">除錯 Rails 應用程式</a></dd>
<dd><a href="configuring.html">Rails 應用程式設定</a></dd>
<dd><a href="command_line.html">Rake 任務與 Rails 命令列工具</a></dd>
<dd><a href="asset_pipeline.html">Asset Pipeline</a></dd>
<dd><a href="working_with_javascript_in_rails.html">在 Rails 使用 JavaScript</a></dd>
<dd><a href="constant_autoloading_and_reloading.html">Constant Autoloading and Reloading</a></dd>
<dt>擴充 Rails</dt>
<dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
<dd><a href="generators.html">客製與新建 Rails 產生器</a></dd>
<dd><a href="rails_application_templates.html">Rails 應用程式模版</a></dd>
<dt>貢獻 Ruby on Rails</dt>
<dd><a href="contributing_to_ruby_on_rails.html">貢獻 Ruby on Rails</a></dd>
<dd><a href="api_documentation_guidelines.html">API 文件準則</a></dd>
<dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails 指南準則</a></dd>
<dt>維護方針</dt>
<dd><a href="maintenance_policy.html">維護方針</a></dd>
<dt>發佈記</dt>
<dd><a href="upgrading_ruby_on_rails.html">升級 Ruby on Rails</a></dd>
<dd><a href="4_2_release_notes.html">Ruby on Rails 4.2 發佈記</a></dd>
<dd><a href="4_1_release_notes.html">Ruby on Rails 4.1 發佈記</a></dd>
<dd><a href="4_0_release_notes.html">Ruby on Rails 4.0 發佈記</a></dd>
<dd><a href="3_2_release_notes.html">Ruby on Rails 3.2 發佈記</a></dd>
<dd><a href="3_1_release_notes.html">Ruby on Rails 3.1 發佈記</a></dd>
<dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 發佈記</a></dd>
<dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 發佈記</a></dd>
<dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 發佈記</a></dd>
<dt>Rails 指南翻譯術語</dt>
<dd><a href="translation_terms.html">翻譯術語</a></dd>
</dl>
</div>
</li>
<li><a class="nav-item" href="//github.com/docrails-tw/guides">貢獻翻譯</a></li>
<li><a class="nav-item" href="contributing_to_ruby_on_rails.html">貢獻</a></li>
<li><a class="nav-item" href="credits.html">致謝</a></li>
<li class="guides-index guides-index-small">
<select class="guides-index-item nav-item">
<option value="index.html">指南目錄</option>
<optgroup label="起步走">
<option value="getting_started.html">Rails 起步走</option>
</optgroup>
<optgroup label="Models">
<option value="active_record_basics.html">Active Record 基礎</option>
<option value="active_record_migrations.html">Active Record 遷移</option>
<option value="active_record_validations.html">Active Record 驗證</option>
<option value="active_record_callbacks.html">Active Record 回呼</option>
<option value="association_basics.html">Active Record 關聯</option>
<option value="active_record_querying.html">Active Record 查詢</option>
</optgroup>
<optgroup label="Views">
<option value="layouts_and_rendering.html">Rails 算繪與版型</option>
<option value="form_helpers.html">Action View 表單輔助方法</option>
</optgroup>
<optgroup label="Controllers">
<option value="action_controller_overview.html">Action Controller 綜覽</option>
<option value="routing.html">Rails 路由:深入淺出</option>
</optgroup>
<optgroup label="深入了解">
<option value="active_support_core_extensions.html">Active Support 核心擴展</option>
<option value="i18n.html">Rails 國際化 API</option>
<option value="action_mailer_basics.html">Action Mailer 基礎</option>
<option value="active_job_basics.html">Active Job 基礎</option>
<option value="security.html">Rails 安全指南</option>
<option value="debugging_rails_applications.html">除錯 Rails 應用程式</option>
<option value="configuring.html">Rails 應用程式設定</option>
<option value="command_line.html">Rake 任務與 Rails 命令列工具</option>
<option value="asset_pipeline.html">Asset Pipeline</option>
<option value="working_with_javascript_in_rails.html">在 Rails 使用 JavaScript</option>
<option value="constant_autoloading_and_reloading.html">Constant Autoloading and Reloading</option>
</optgroup>
<optgroup label="擴充 Rails">
<option value="rails_on_rack.html">Rails on Rack</option>
<option value="generators.html">客製與新建 Rails 產生器</option>
<option value="rails_application_templates.html">Rails 應用程式模版</option>
</optgroup>
<optgroup label="貢獻 Ruby on Rails">
<option value="contributing_to_ruby_on_rails.html">貢獻 Ruby on Rails</option>
<option value="api_documentation_guidelines.html">API 文件準則</option>
<option value="ruby_on_rails_guides_guidelines.html">Ruby on Rails 指南準則</option>
</optgroup>
<optgroup label="維護方針">
<option value="maintenance_policy.html">維護方針</option>
</optgroup>
<optgroup label="發佈記">
<option value="upgrading_ruby_on_rails.html">升級 Ruby on Rails</option>
<option value="4_2_release_notes.html">Ruby on Rails 4.2 發佈記</option>
<option value="4_1_release_notes.html">Ruby on Rails 4.1 發佈記</option>
<option value="4_0_release_notes.html">Ruby on Rails 4.0 發佈記</option>
<option value="3_2_release_notes.html">Ruby on Rails 3.2 發佈記</option>
<option value="3_1_release_notes.html">Ruby on Rails 3.1 發佈記</option>
<option value="3_0_release_notes.html">Ruby on Rails 3.0 發佈記</option>
<option value="2_3_release_notes.html">Ruby on Rails 2.3 發佈記</option>
<option value="2_2_release_notes.html">Ruby on Rails 2.2 發佈記</option>
</optgroup>
<optgroup label="Rails 指南翻譯術語">
<option value="translation_terms.html">翻譯術語</option>
</optgroup>
</select>
</li>
</ul>
</div>
</div>
</div>
<hr class="hide">
<div id="feature">
<div class="wrapper">
<h2>Ruby on Rails 4.0 Release Notes</h2><p>Highlights in Rails 4.0:</p>
<ul>
<li>Ruby 2.0 preferred; 1.9.3+ required</li>
<li>Strong Parameters</li>
<li>Turbolinks</li>
<li>Russian Doll Caching</li>
</ul>
<p>These release notes cover only the major changes. To know about various bug fixes and changes, please refer to the change logs or check out the <a href="https://github.com/rails/rails/commits/4-0-stable">list of commits</a> in the main Rails repository on GitHub.</p>
<div id="subCol">
<h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
<ol class="chapters">
<li><a href="#upgrading-to-rails-4-0">Upgrading to Rails 4.0</a></li>
<li>
<a href="#creating-a-rails-4-0-application">Creating a Rails 4.0 application</a>
<ul>
<li><a href="#vendoring-gems">Vendoring Gems</a></li>
<li><a href="#living-on-the-edge">Living on the Edge</a></li>
</ul>
</li>
<li>
<a href="#major-features">Major Features</a>
<ul>
<li><a href="#upgrade">Upgrade</a></li>
<li><a href="#actionpack">ActionPack</a></li>
<li><a href="#general">General</a></li>
<li><a href="#security">Security</a></li>
</ul>
</li>
<li><a href="#extraction-of-features-to-gems">Extraction of features to gems</a></li>
<li><a href="#documentation">Documentation</a></li>
<li>
<a href="#railties">Railties</a>
<ul>
<li><a href="#railties-notable-changes">Notable changes</a></li>
<li><a href="#railties-deprecations">Deprecations</a></li>
</ul>
</li>
<li>
<a href="#action-mailer">Action Mailer</a>
<ul>
<li><a href="#action-mailer-notable-changes">Notable changes</a></li>
<li><a href="#action-mailer-deprecations">Deprecations</a></li>
</ul>
</li>
<li>
<a href="#active-model">Active Model</a>
<ul>
<li><a href="#active-model-notable-changes">Notable changes</a></li>
<li><a href="#active-model-deprecations">Deprecations</a></li>
</ul>
</li>
<li>
<a href="#active-support">Active Support</a>
<ul>
<li><a href="#active-support-notable-changes">Notable changes</a></li>
<li><a href="#active-support-deprecations">Deprecations</a></li>
</ul>
</li>
<li>
<a href="#action-pack">Action Pack</a>
<ul>
<li><a href="#action-pack-notable-changes">Notable changes</a></li>
<li><a href="#action-pack-deprecations">Deprecations</a></li>
</ul>
</li>
<li>
<a href="#active-record">Active Record</a>
<ul>
<li><a href="#active-record-notable-changes">Notable changes</a></li>
<li><a href="#active-record-deprecations">Deprecations</a></li>
</ul>
</li>
<li><a href="#credits">Credits</a></li>
</ol>
</div>
</div>
</div>
<div id="container">
<div class="wrapper">
<div id="mainCol">
<h3 id="upgrading-to-rails-4-0">1 Upgrading to Rails 4.0</h3><p>If you're upgrading an existing application, it's a great idea to have good test coverage before going in. You should also first upgrade to Rails 3.2 in case you haven't and make sure your application still runs as expected before attempting an update to Rails 4.0. A list of things to watch out for when upgrading is available in the <a href="upgrading_ruby_on_rails.html#upgrading-from-rails-3-2-to-rails-4-0">Upgrading Ruby on Rails</a> guide.</p><h3 id="creating-a-rails-4-0-application">2 Creating a Rails 4.0 application</h3><div class="code_container">
<pre class="brush: plain; gutter: false; toolbar: false">
You should have the 'rails' RubyGem installed
$ rails new myapp
$ cd myapp
</pre>
</div>
<h4 id="vendoring-gems">2.1 Vendoring Gems</h4><p>Rails now uses a <code>Gemfile</code> in the application root to determine the gems you require for your application to start. This <code>Gemfile</code> is processed by the <a href="https://github.com/carlhuda/bundler">Bundler</a> gem, which then installs all your dependencies. It can even install all the dependencies locally to your application so that it doesn't depend on the system gems.</p><p>More information: <a href="http://gembundler.com">Bundler homepage</a></p><h4 id="living-on-the-edge">2.2 Living on the Edge</h4><p><code>Bundler</code> and <code>Gemfile</code> makes freezing your Rails application easy as pie with the new dedicated <code>bundle</code> command. If you want to bundle straight from the Git repository, you can pass the <code>--edge</code> flag:</p><div class="code_container">
<pre class="brush: plain; gutter: false; toolbar: false">
$ rails new myapp --edge
</pre>
</div>
<p>If you have a local checkout of the Rails repository and want to generate an application using that, you can pass the <code>--dev</code> flag:</p><div class="code_container">
<pre class="brush: plain; gutter: false; toolbar: false">
$ ruby /path/to/rails/railties/bin/rails new myapp --dev
</pre>
</div>
<h3 id="major-features">3 Major Features</h3><p><a href="http://guides.rubyonrails.org/images/rails4_features.png"><img src="images/rails4_features.png" alt="Rails 4.0"></a></p><h4 id="upgrade">3.1 Upgrade</h4>
<ul>
<li>
<strong>Ruby 1.9.3</strong> (<a href="https://github.com/rails/rails/commit/a0380e808d3dbd2462df17f5d3b7fcd8bd812496">commit</a>) - Ruby 2.0 preferred; 1.9.3+ required</li>
<li>
<strong><a href="http://www.youtube.com/watch?v=z6YgD6tVPQs">New deprecation policy</a></strong> - Deprecated features are warnings in Rails 4.0 and will be removed in Rails 4.1.</li>
<li>
<strong>ActionPack page and action caching</strong> (<a href="https://github.com/rails/rails/commit/b0a7068564f0c95e7ef28fc39d0335ed17d93e90">commit</a>) - Page and action caching are extracted to a separate gem. Page and action caching requires too much manual intervention (manually expiring caches when the underlying model objects are updated). Instead, use Russian doll caching.</li>
<li>
<strong>ActiveRecord observers</strong> (<a href="https://github.com/rails/rails/commit/ccecab3ba950a288b61a516bf9b6962e384aae0b">commit</a>) - Observers are extracted to a separate gem. Observers are only needed for page and action caching, and can lead to spaghetti code.</li>
<li>
<strong>ActiveRecord session store</strong> (<a href="https://github.com/rails/rails/commit/0ffe19056c8e8b2f9ae9d487b896cad2ce9387ad">commit</a>) - The ActiveRecord session store is extracted to a separate gem. Storing sessions in SQL is costly. Instead, use cookie sessions, memcache sessions, or a custom session store.</li>
<li>
<strong>ActiveModel mass assignment protection</strong> (<a href="https://github.com/rails/rails/commit/f8c9a4d3e88181cee644f91e1342bfe896ca64c6">commit</a>) - Rails 3 mass assignment protection is deprecated. Instead, use strong parameters.</li>
<li>
<strong>ActiveResource</strong> (<a href="https://github.com/rails/rails/commit/f1637bf2bb00490203503fbd943b73406e043d1d">commit</a>) - ActiveResource is extracted to a separate gem. ActiveResource was not widely used.</li>
<li>
<strong>vendor/plugins removed</strong> (<a href="https://github.com/rails/rails/commit/853de2bd9ac572735fa6cf59fcf827e485a231c3">commit</a>) - Use a Gemfile to manage installed gems.</li>
</ul>
<h4 id="actionpack">3.2 ActionPack</h4>
<ul>
<li>
<strong>Strong parameters</strong> (<a href="https://github.com/rails/rails/commit/a8f6d5c6450a7fe058348a7f10a908352bb6c7fc">commit</a>) - Only allow whitelisted parameters to update model objects (<code>params.permit(:title, :text)</code>).</li>
<li>
<strong>Routing concerns</strong> (<a href="https://github.com/rails/rails/commit/0dd24728a088fcb4ae616bb5d62734aca5276b1b">commit</a>) - In the routing DSL, factor out common subroutes (<code>comments</code> from <code>/posts/1/comments</code> and <code>/videos/1/comments</code>).</li>
<li>
<strong>ActionController::Live</strong> (<a href="https://github.com/rails/rails/commit/af0a9f9eefaee3a8120cfd8d05cbc431af376da3">commit</a>) - Stream JSON with <code>response.stream</code>.</li>
<li>
<strong>Declarative ETags</strong> (<a href="https://github.com/rails/rails/commit/ed5c938fa36995f06d4917d9543ba78ed506bb8d">commit</a>) - Add controller-level etag additions that will be part of the action etag computation</li>
<li>
<strong><a href="http://signalvnoise.com/posts/3113-how-key-based-cache-expiration-works">Russian doll caching</a></strong> (<a href="https://github.com/rails/rails/commit/4154bf012d2bec2aae79e4a49aa94a70d3e91d49">commit</a>) - Cache nested fragments of views. Each fragment expires based on a set of dependencies (a cache key). The cache key is usually a template version number and a model object.</li>
<li>
<strong>Turbolinks</strong> (<a href="https://github.com/rails/rails/commit/e35d8b18d0649c0ecc58f6b73df6b3c8d0c6bb74">commit</a>) - Serve only one initial HTML page. When the user navigates to another page, use pushState to update the URL and use AJAX to update the title and body.</li>
<li>
<strong>Decouple ActionView from ActionController</strong> (<a href="https://github.com/rails/rails/commit/78b0934dd1bb84e8f093fb8ef95ca99b297b51cd">commit</a>) - ActionView was decoupled from ActionPack and will be moved to a separated gem in Rails 4.1.</li>
<li>
<strong>Do not depend on ActiveModel</strong> (<a href="https://github.com/rails/rails/commit/166dbaa7526a96fdf046f093f25b0a134b277a68">commit</a>) - ActionPack no longer depends on ActiveModel.</li>
</ul>
<h4 id="general">3.3 General</h4>
<ul>
<li>
<strong>ActiveModel::Model</strong> (<a href="https://github.com/rails/rails/commit/3b822e91d1a6c4eab0064989bbd07aae3a6d0d08">commit</a>) - <code>ActiveModel::Model</code>, a mixin to make normal Ruby objects to work with ActionPack out of box (ex. for <code>form_for</code>)</li>
<li>
<strong>New scope API</strong> (<a href="https://github.com/rails/rails/commit/50cbc03d18c5984347965a94027879623fc44cce">commit</a>) - Scopes must always use callables.</li>
<li>
<strong>Schema cache dump</strong> (<a href="https://github.com/rails/rails/commit/5ca4fc95818047108e69e22d200e7a4a22969477">commit</a>) - To improve Rails boot time, instead of loading the schema directly from the database, load the schema from a dump file.</li>
<li>
<strong>Support for specifying transaction isolation level</strong> (<a href="https://github.com/rails/rails/commit/392eeecc11a291e406db927a18b75f41b2658253">commit</a>) - Choose whether repeatable reads or improved performance (less locking) is more important.</li>
<li>
<strong>Dalli</strong> (<a href="https://github.com/rails/rails/commit/82663306f428a5bbc90c511458432afb26d2f238">commit</a>) - Use Dalli memcache client for the memcache store.</li>
<li>
<strong>Notifications start & finish</strong> (<a href="https://github.com/rails/rails/commit/f08f8750a512f741acb004d0cebe210c5f949f28">commit</a>) - Active Support instrumentation reports start and finish notifications to subscribers.</li>
<li>
<strong>Thread safe by default</strong> (<a href="https://github.com/rails/rails/commit/5d416b907864d99af55ebaa400fff217e17570cd">commit</a>) - Rails can run in threaded app servers without additional configuration. Note: Check that the gems you are using are threadsafe.</li>
<li>
<strong>PATCH verb</strong> (<a href="https://github.com/rails/rails/commit/eed9f2539e3ab5a68e798802f464b8e4e95e619e">commit</a>) - In Rails, PATCH replaces PUT. PATCH is used for partial updates of resources.</li>
</ul>
<h4 id="security">3.4 Security</h4>
<ul>
<li>
<strong>match do not catch all</strong> (<a href="https://github.com/rails/rails/commit/90d2802b71a6e89aedfe40564a37bd35f777e541">commit</a>) - In the routing DSL, match requires the HTTP verb or verbs to be specified.</li>
<li>
<strong>html entities escaped by default</strong> (<a href="https://github.com/rails/rails/commit/5f189f41258b83d49012ec5a0678d827327e7543">commit</a>) - Strings rendered in erb are escaped unless wrapped with <code>raw</code> or <code>html_safe</code> is called.</li>
<li>
<strong>New security headers</strong> (<a href="https://github.com/rails/rails/commit/6794e92b204572d75a07bd6413bdae6ae22d5a82">commit</a>) - Rails sends the following headers with every HTTP request: <code>X-Frame-Options</code> (prevents clickjacking by forbidding the browser from embedding the page in a frame), <code>X-XSS-Protection</code> (asks the browser to halt script injection) and <code>X-Content-Type-Options</code> (prevents the browser from opening a jpeg as an exe).</li>
</ul>
<h3 id="extraction-of-features-to-gems">4 Extraction of features to gems</h3><p>In Rails 4.0, several features have been extracted into gems. You can simply add the extracted gems to your <code>Gemfile</code> to bring the functionality back.</p>
<ul>
<li>Hash-based & Dynamic finder methods (<a href="https://github.com/rails/activerecord-deprecated_finders">GitHub</a>)</li>
<li>Mass assignment protection in Active Record models (<a href="https://github.com/rails/protected_attributes">GitHub</a>, <a href="https://github.com/rails/rails/pull/7251">Pull Request</a>)</li>
<li>ActiveRecord::SessionStore (<a href="https://github.com/rails/activerecord-session_store">GitHub</a>, <a href="https://github.com/rails/rails/pull/7436">Pull Request</a>)</li>
<li>Active Record Observers (<a href="https://github.com/rails/rails-observers">GitHub</a>, <a href="https://github.com/rails/rails/commit/39e85b3b90c58449164673909a6f1893cba290b2">Commit</a>)</li>
<li>Active Resource (<a href="https://github.com/rails/activeresource">GitHub</a>, <a href="https://github.com/rails/rails/pull/572">Pull Request</a>, <a href="http://yetimedia.tumblr.com/post/35233051627/activeresource-is-dead-long-live-activeresource">Blog</a>)</li>
<li>Action Caching (<a href="https://github.com/rails/actionpack-action_caching">GitHub</a>, <a href="https://github.com/rails/rails/pull/7833">Pull Request</a>)</li>
<li>Page Caching (<a href="https://github.com/rails/actionpack-page_caching">GitHub</a>, <a href="https://github.com/rails/rails/pull/7833">Pull Request</a>)</li>
<li>Sprockets (<a href="https://github.com/rails/sprockets-rails">GitHub</a>)</li>
<li>Performance tests (<a href="https://github.com/rails/rails-perftest">GitHub</a>, <a href="https://github.com/rails/rails/pull/8876">Pull Request</a>)</li>
</ul>
<h3 id="documentation">5 Documentation</h3>
<ul>
<li><p>Guides are rewritten in GitHub Flavored Markdown.</p></li>
<li><p>Guides have a responsive design.</p></li>
</ul>
<h3 id="railties">6 Railties</h3><p>Please refer to the <a href="https://github.com/rails/rails/blob/4-0-stable/railties/CHANGELOG.md">Changelog</a> for detailed changes.</p><h4 id="railties-notable-changes">6.1 Notable changes</h4>
<ul>
<li><p>New test locations <code>test/models</code>, <code>test/helpers</code>, <code>test/controllers</code>, and <code>test/mailers</code>. Corresponding rake tasks added as well. (<a href="https://github.com/rails/rails/pull/7878">Pull Request</a>)</p></li>
<li><p>Your app's executables now live in the <code>bin/</code> directory. Run <code>rake rails:update:bin</code> to get <code>bin/bundle</code>, <code>bin/rails</code>, and <code>bin/rake</code>.</p></li>
<li><p>Threadsafe on by default</p></li>
<li><p>Ability to use a custom builder by passing <code>--builder</code> (or <code>-b</code>) to
<code>rails new</code> has been removed. Consider using application templates
instead. (<a href="https://github.com/rails/rails/pull/9401">Pull Request</a>)</p></li>
</ul>
<h4 id="railties-deprecations">6.2 Deprecations</h4>
<ul>
<li><p><code>config.threadsafe!</code> is deprecated in favor of <code>config.eager_load</code> which provides a more fine grained control on what is eager loaded.</p></li>
<li><p><code>Rails::Plugin</code> has gone. Instead of adding plugins to <code>vendor/plugins</code> use gems or bundler with path or git dependencies.</p></li>
</ul>
<h3 id="action-mailer">7 Action Mailer</h3><p>Please refer to the <a href="https://github.com/rails/rails/blob/4-0-stable/actionmailer/CHANGELOG.md">Changelog</a> for detailed changes.</p><h4 id="action-mailer-notable-changes">7.1 Notable changes</h4><h4 id="action-mailer-deprecations">7.2 Deprecations</h4><h3 id="active-model">8 Active Model</h3><p>Please refer to the <a href="https://github.com/rails/rails/blob/4-0-stable/activemodel/CHANGELOG.md">Changelog</a> for detailed changes.</p><h4 id="active-model-notable-changes">8.1 Notable changes</h4>
<ul>
<li><p>Add <code>ActiveModel::ForbiddenAttributesProtection</code>, a simple module to protect attributes from mass assignment when non-permitted attributes are passed.</p></li>
<li><p>Added <code>ActiveModel::Model</code>, a mixin to make Ruby objects work with Action Pack out of box.</p></li>
</ul>
<h4 id="active-model-deprecations">8.2 Deprecations</h4><h3 id="active-support">9 Active Support</h3><p>Please refer to the <a href="https://github.com/rails/rails/blob/4-0-stable/activesupport/CHANGELOG.md">Changelog</a> for detailed changes.</p><h4 id="active-support-notable-changes">9.1 Notable changes</h4>
<ul>
<li><p>Replace deprecated <code>memcache-client</code> gem with <code>dalli</code> in <code>ActiveSupport::Cache::MemCacheStore</code>.</p></li>
<li><p>Optimize <code>ActiveSupport::Cache::Entry</code> to reduce memory and processing overhead.</p></li>
<li><p>Inflections can now be defined per locale. <code>singularize</code> and <code>pluralize</code> accept locale as an extra argument.</p></li>
<li><p><code>Object#try</code> will now return nil instead of raise a NoMethodError if the receiving object does not implement the method, but you can still get the old behavior by using the new <code>Object#try!</code>.</p></li>
<li><p><code>String#to_date</code> now raises <code>ArgumentError: invalid date</code> instead of <code>NoMethodError: undefined method 'div' for nil:NilClass</code>
when given an invalid date. It is now the same as <code>Date.parse</code>, and it accepts more invalid dates than 3.x, such as:</p></li>
</ul>
<div class="code_container">
<pre class="brush: plain; gutter: false; toolbar: false">
# ActiveSupport 3.x
"asdf".to_date # => NoMethodError: undefined method `div' for nil:NilClass
"333".to_date # => NoMethodError: undefined method `div' for nil:NilClass
# ActiveSupport 4
"asdf".to_date # => ArgumentError: invalid date
"333".to_date # => Fri, 29 Nov 2013
</pre>
</div>
<h4 id="active-support-deprecations">9.2 Deprecations</h4>
<ul>
<li><p>Deprecate <code>ActiveSupport::TestCase#pending</code> method, use <code>skip</code> from MiniTest instead.</p></li>
<li><p><code>ActiveSupport::Benchmarkable#silence</code> has been deprecated due to its lack of thread safety. It will be removed without replacement in Rails 4.1.</p></li>
<li><p><code>ActiveSupport::JSON::Variable</code> is deprecated. Define your own <code>#as_json</code> and <code>#encode_json</code> methods for custom JSON string literals.</p></li>
<li><p>Deprecates the compatibility method <code>Module#local_constant_names</code>, use <code>Module#local_constants</code> instead (which returns symbols).</p></li>
<li><p><code>BufferedLogger</code> is deprecated. Use <code>ActiveSupport::Logger</code>, or the logger from Ruby standard library.</p></li>
<li><p>Deprecate <code>assert_present</code> and <code>assert_blank</code> in favor of <code>assert object.blank?</code> and <code>assert object.present?</code></p></li>
</ul>
<h3 id="action-pack">10 Action Pack</h3><p>Please refer to the <a href="https://github.com/rails/rails/blob/4-0-stable/actionpack/CHANGELOG.md">Changelog</a> for detailed changes.</p><h4 id="action-pack-notable-changes">10.1 Notable changes</h4>
<ul>
<li>Change the stylesheet of exception pages for development mode. Additionally display also the line of code and fragment that raised the exception in all exceptions pages.</li>
</ul>
<h4 id="action-pack-deprecations">10.2 Deprecations</h4><h3 id="active-record">11 Active Record</h3><p>Please refer to the <a href="https://github.com/rails/rails/blob/4-0-stable/activerecord/CHANGELOG.md">Changelog</a> for detailed changes.</p><h4 id="active-record-notable-changes">11.1 Notable changes</h4>
<ul>
<li>
<p>Improve ways to write <code>change</code> migrations, making the old <code>up</code> & <code>down</code> methods no longer necessary.</p>
<ul>
<li>The methods <code>drop_table</code> and <code>remove_column</code> are now reversible, as long as the necessary information is given.
The method <code>remove_column</code> used to accept multiple column names; instead use <code>remove_columns</code> (which is not revertible).
The method <code>change_table</code> is also reversible, as long as its block doesn't call <code>remove</code>, <code>change</code> or <code>change_default</code>
</li>
<li>New method <code>reversible</code> makes it possible to specify code to be run when migrating up or down.
See the <a href="https://github.com/rails/rails/blob/master/guides/source/active_record_migrations.md#using-reversible">Guide on Migration</a>
</li>
<li>New method <code>revert</code> will revert a whole migration or the given block.
If migrating down, the given migration / block is run normally.
See the <a href="https://github.com/rails/rails/blob/master/guides/source/active_record_migrations.md#reverting-previous-migrations">Guide on Migration</a>
</li>
</ul>
</li>
<li><p>Adds PostgreSQL array type support. Any datatype can be used to create an array column, with full migration and schema dumper support.</p></li>
<li><p>Add <code>Relation#load</code> to explicitly load the record and return <code>self</code>.</p></li>
<li><p><code>Model.all</code> now returns an <code>ActiveRecord::Relation</code>, rather than an array of records. Use <code>Relation#to_a</code> if you really want an array. In some specific cases, this may cause breakage when upgrading.</p></li>
<li><p>Added <code>ActiveRecord::Migration.check_pending!</code> that raises an error if migrations are pending.</p></li>
<li>
<p>Added custom coders support for <code>ActiveRecord::Store</code>. Now you can set your custom coder like this:</p>
<div class="code_container">
<pre class="brush: plain; gutter: false; toolbar: false">
store :settings, accessors: [ :color, :homepage ], coder: JSON
</pre>
</div>
</li>
<li><p><code>mysql</code> and <code>mysql2</code> connections will set <code>SQL_MODE=STRICT_ALL_TABLES</code> by default to avoid silent data loss. This can be disabled by specifying <code>strict: false</code> in your <code>database.yml</code>.</p></li>
<li><p>Remove IdentityMap.</p></li>
<li><p>Remove automatic execution of EXPLAIN queries. The option <code>active_record.auto_explain_threshold_in_seconds</code> is no longer used and should be removed.</p></li>
<li><p>Adds <code>ActiveRecord::NullRelation</code> and <code>ActiveRecord::Relation#none</code> implementing the null object pattern for the Relation class.</p></li>
<li><p>Added <code>create_join_table</code> migration helper to create HABTM join tables.</p></li>
<li><p>Allows PostgreSQL hstore records to be created.</p></li>
</ul>
<h4 id="active-record-deprecations">11.2 Deprecations</h4>
<ul>
<li><p>Deprecated the old-style hash based finder API. This means that methods which previously accepted "finder options" no longer do.</p></li>
<li>
<p>All dynamic methods except for <code>find_by_...</code> and <code>find_by_...!</code> are deprecated. Here's
how you can rewrite the code:</p>
<ul>
<li>
<code>find_all_by_...</code> can be rewritten using <code>where(...)</code>.</li>
<li>
<code>find_last_by_...</code> can be rewritten using <code>where(...).last</code>.</li>
<li>
<code>scoped_by_...</code> can be rewritten using <code>where(...)</code>.</li>
<li>
<code>find_or_initialize_by_...</code> can be rewritten using <code>find_or_initialize_by(...)</code>.</li>
<li>
<code>find_or_create_by_...</code> can be rewritten using <code>find_or_create_by(...)</code>.</li>
<li>
<code>find_or_create_by_...!</code> can be rewritten using <code>find_or_create_by!(...)</code>.</li>
</ul>
</li>
</ul>
<h3 id="credits">12 Credits</h3><p>See the <a href="http://contributors.rubyonrails.org/">full list of contributors to Rails</a> for the many people who spent many hours making Rails, the stable and robust framework it is. Kudos to all of them.</p>
<h3>反饋</h3>
<p>
歡迎幫忙改善指南的品質。
</p>
<p>
如發現任何錯誤之處,歡迎修正。開始貢獻前,可以先閱讀<a href="http://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html#contributing-to-the-rails-documentation">貢獻指南:文件</a>。
</p>
<p>翻譯如有錯誤,深感抱歉,歡迎 <a href="https://github.com/docrails-tw/guides/fork">Fork</a> 修正,或至此處<a href="https://github.com/docsrails-tw/guides/issues/new">回報</a>。</p>
<p>
文章可能有未完成或過時的內容。請先檢查 <a href="http://edgeguides.rubyonrails.org">Edge Guides</a> 來確定問題在 master 是否已經修掉了。再上 master 補上缺少的文件。內容參考 <a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails 指南準則</a>來了解行文風格。
</p>
<p>最後,任何關於 Ruby on Rails 文件的討論,歡迎至 <a href="http://groups.google.com/group/rubyonrails-docs">rubyonrails-docs 郵件論壇</a>。
</p>
</div>
</div>
</div>
<hr class="hide">
<div id="footer">
<div class="wrapper">
<p>本著作係採用<a href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh_TW">創用 CC 姓名標示-相同方式分享 4.0 國際授權條款</a>授權。</p>
<p>“Rails”、“Ruby on Rails”,以及 Rails logo 為 David Heinemeier Hansson 的商標。版權所有。</p>
</div>
</div>
<script src="javascripts/jquery.min.js"></script>
<script src="javascripts/responsive-tables.js"></script>
<script src="javascripts/guides.js"></script>
<script src="javascripts/syntaxhighlighter/shCore.js"></script>
<script src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
<script src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
<script src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
<script src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
<script type="text/javascript">
SyntaxHighlighter.all();
$(guidesIndex.bind);
</script>
<script>
(function(i,s,o,g,r,a,m){i["GoogleAnalyticsObject"]=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,"script","//www.google-analytics.com/analytics.js","ga");
ga("create", "UA-49903900-1", "auto");
ga("require", "displayfeatures");
ga("send", "pageview");
</script>
</body>
</html>