/
4_0_release_notes.html
501 lines (479 loc) · 34.8 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
<!DOCTYPE html>
<html lang="en">
<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 Guides</title>
<link rel="stylesheet" type="text/css" href="stylesheets/style.css" data-turbolinks-track="reload">
<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print">
<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" data-turbolinks-track="reload">
<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" data-turbolinks-track="reload">
<link rel="stylesheet" type="text/css" href="stylesheets/fixes.css" data-turbolinks-track="reload">
<link href="images/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<script src="javascripts/syntaxhighlighter.js" data-turbolinks-track="reload"></script>
<script src="javascripts/turbolinks.js" data-turbolinks-track="reload"></script>
<script src="javascripts/guides.js" data-turbolinks-track="reload"></script>
<script src="javascripts/responsive-tables.js" data-turbolinks-track="reload"></script>
</head>
<body class="guide">
<div>
<img src="images/edge_badge.png" alt="edge-badge" id="edge-badge" />
</div>
<div id="topNav">
<div class="wrapper">
<strong class="more-info-label">Veja mais em <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
<span class="red-button more-info-button">
Mais Ruby on Rails
</span>
<ul class="more-info-links s-hidden">
<li class="more-info"><a href="https://weblog.rubyonrails.org/">Blog</a></li>
<li class="more-info"><a href="https://guides.rubyonrails.org/">Guia</a></li>
<li class="more-info"><a href="http://api.rubyonrails.org/">API</a></li>
<li class="more-info"><a href="https://stackoverflow.com/questions/tagged/ruby-on-rails">Pedir ajuda</a></li>
<li class="more-info"><a href="https://github.com/rails/rails">Contribuir no GitHub</a></li>
</ul>
</div>
</div>
<div id="header">
<div class="wrapper clearfix">
<h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
<ul class="nav">
<li><a class="nav-item" href="index.html">Home</a></li>
<li class="guides-index guides-index-large">
<a href="index.html" id="guidesMenu" class="guides-index-item nav-item">Guias</a>
<div id="guides" class="clearfix" style="display: none;">
<hr />
<div class="guides-section-container">
<div class="guides-section">
<dt>Comece Aqui</dt>
</div>
<div class="guides-section">
<dt>Models</dt>
</div>
<div class="guides-section">
<dt>Views</dt>
</div>
<div class="guides-section">
<dt>Controllers</dt>
</div>
<div class="guides-section">
<dt>Other Components</dt>
</div>
<div class="guides-section">
<dt>Digging Deeper</dt>
</div>
<div class="guides-section">
<dt>Extending Rails</dt>
<dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
<dd><a href="generators.html">Creating and Customizing Rails Generators & Templates</a></dd>
</div>
<div class="guides-section">
<dt>Contributions</dt>
<dd><a href="contributing_to_ruby_on_rails.html">Contributing to Ruby on Rails</a></dd>
<dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
<dd><a href="ruby_on_rails_guides_guidelines.html">Guides Guidelines</a></dd>
</div>
<div class="guides-section">
<dt>Policies</dt>
<dd><a href="maintenance_policy.html">Maintenance Policy</a></dd>
</div>
<div class="guides-section">
<dt>Release Notes</dt>
<dd><a href="upgrading_ruby_on_rails.html">Upgrading Ruby on Rails</a></dd>
<dd><a href="5_2_release_notes.html">Version 5.2 - April 2018</a></dd>
<dd><a href="5_1_release_notes.html">Version 5.1 - April 2017</a></dd>
<dd><a href="5_0_release_notes.html">Version 5.0 - June 2016</a></dd>
<dd><a href="4_2_release_notes.html">Version 4.2 - December 2014</a></dd>
<dd><a href="4_1_release_notes.html">Version 4.1 - April 2014</a></dd>
<dd><a href="4_0_release_notes.html">Version 4.0 - June 2013</a></dd>
<dd><a href="3_2_release_notes.html">Version 3.2 - January 2012</a></dd>
<dd><a href="3_1_release_notes.html">Version 3.1 - August 2011</a></dd>
<dd><a href="3_0_release_notes.html">Version 3.0 - August 2010</a></dd>
<dd><a href="2_3_release_notes.html">Version 2.3 - March 2009</a></dd>
<dd><a href="2_2_release_notes.html">Version 2.2 - November 2008</a></dd>
</div>
</div>
</div>
</li>
<li><a class="nav-item" href="contributing_to_ruby_on_rails.html">Contribua</a></li>
<li class="guides-index guides-index-small">
<select class="guides-index-item nav-item">
<option value="index.html">Guias</option>
<optgroup label="Comece Aqui">
</optgroup>
<optgroup label="Models">
</optgroup>
<optgroup label="Views">
</optgroup>
<optgroup label="Controllers">
</optgroup>
<optgroup label="Other Components">
</optgroup>
<optgroup label="Digging Deeper">
</optgroup>
<optgroup label="Extending Rails">
<option value="rails_on_rack.html">Rails on Rack</option>
<option value="generators.html">Creating and Customizing Rails Generators & Templates</option>
</optgroup>
<optgroup label="Contributions">
<option value="contributing_to_ruby_on_rails.html">Contributing to Ruby on Rails</option>
<option value="api_documentation_guidelines.html">API Documentation Guidelines</option>
<option value="ruby_on_rails_guides_guidelines.html">Guides Guidelines</option>
</optgroup>
<optgroup label="Policies">
<option value="maintenance_policy.html">Maintenance Policy</option>
</optgroup>
<optgroup label="Release Notes">
<option value="upgrading_ruby_on_rails.html">Upgrading Ruby on Rails</option>
<option value="5_2_release_notes.html">Version 5.2 - April 2018</option>
<option value="5_1_release_notes.html">Version 5.1 - April 2017</option>
<option value="5_0_release_notes.html">Version 5.0 - June 2016</option>
<option value="4_2_release_notes.html">Version 4.2 - December 2014</option>
<option value="4_1_release_notes.html">Version 4.1 - April 2014</option>
<option value="4_0_release_notes.html">Version 4.0 - June 2013</option>
<option value="3_2_release_notes.html">Version 3.2 - January 2012</option>
<option value="3_1_release_notes.html">Version 3.1 - August 2011</option>
<option value="3_0_release_notes.html">Version 3.0 - August 2010</option>
<option value="2_3_release_notes.html">Version 2.3 - March 2009</option>
<option value="2_2_release_notes.html">Version 2.2 - November 2008</option>
</optgroup>
</select>
</li>
</ul>
</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 learn 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"><a class="anchorlink" href="#upgrading-to-rails-4-0">1 Upgrading to Rails 4.0</a></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"><a class="anchorlink" href="#creating-a-rails-4-0-application">2 Creating a Rails 4.0 application</a></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"><a class="anchorlink" href="#vendoring-gems">2.1 Vendoring Gems</a></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="https://bundler.io">Bundler homepage</a></p><h4 id="living-on-the-edge"><a class="anchorlink" href="#living-on-the-edge">2.2 Living on the Edge</a></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"><a class="anchorlink" href="#major-features">3 Major Features</a></h3><p><a href="https://guides.rubyonrails.org/images/4_0_release_notes/rails4_features.png"><img src="images/4_0_release_notes/rails4_features.png" alt="Rails 4.0"></a></p><h4 id="upgrade"><a class="anchorlink" href="#upgrade">3.1 Upgrade</a></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="https://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 <code>Gemfile</code> to manage installed gems.</li>
</ul>
<h4 id="actionpack"><a class="anchorlink" href="#actionpack">3.2 ActionPack</a></h4>
<ul>
<li>
<strong>Strong parameters</strong> (<a href="https://github.com/rails/rails/commit/a8f6d5c6450a7fe058348a7f10a908352bb6c7fc">commit</a>) - Only allow permitted 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://37signals.com/svn/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"><a class="anchorlink" href="#general">3.3 General</a></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.</li>
</ul>
<div class="note"><p>Check that the gems you are using are threadsafe.</p></div>
<ul>
<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"><a class="anchorlink" href="#security">3.4 Security</a></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"><a class="anchorlink" href="#extraction-of-features-to-gems">4 Extraction of features to gems</a></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-blog-blog.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"><a class="anchorlink" href="#documentation">5 Documentation</a></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"><a class="anchorlink" href="#railties">6 Railties</a></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"><a class="anchorlink" href="#railties-notable-changes">6.1 Notable changes</a></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"><a class="anchorlink" href="#railties-deprecations">6.2 Deprecations</a></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"><a class="anchorlink" href="#action-mailer">7 Action Mailer</a></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"><a class="anchorlink" href="#action-mailer-notable-changes">7.1 Notable changes</a></h4><h4 id="action-mailer-deprecations"><a class="anchorlink" href="#action-mailer-deprecations">7.2 Deprecations</a></h4><h3 id="active-model"><a class="anchorlink" href="#active-model">8 Active Model</a></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"><a class="anchorlink" href="#active-model-notable-changes">8.1 Notable changes</a></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"><a class="anchorlink" href="#active-model-deprecations">8.2 Deprecations</a></h4><h3 id="active-support"><a class="anchorlink" href="#active-support">9 Active Support</a></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"><a class="anchorlink" href="#active-support-notable-changes">9.1 Notable changes</a></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: ruby; 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"><a class="anchorlink" href="#active-support-deprecations">9.2 Deprecations</a></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"><a class="anchorlink" href="#action-pack">10 Action Pack</a></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"><a class="anchorlink" href="#action-pack-notable-changes">10.1 Notable changes</a></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"><a class="anchorlink" href="#action-pack-deprecations">10.2 Deprecations</a></h4><h3 id="active-record"><a class="anchorlink" href="#active-record">11 Active Record</a></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"><a class="anchorlink" href="#active-record-notable-changes">11.1 Notable changes</a></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"><a class="anchorlink" href="#active-record-deprecations">11.2 Deprecations</a></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"><a class="anchorlink" href="#credits">12 Credits</a></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>Feedback</h3>
<p>
You're encouraged to help improve the quality of this guide.
</p>
<p>
Please contribute if you see any typos or factual errors.
To get started, you can read our <a href="https://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html#contributing-to-the-rails-documentation">documentation contributions</a> section.
</p>
<p>
You may also find incomplete content or stuff that is not up to date.
Please do add any missing documentation for master. Make sure to check
<a href="https://edgeguides.rubyonrails.org">Edge Guides</a> first to verify
if the issues are already fixed or not on the master branch.
Check the <a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a>
for style and conventions.
</p>
<p>
If for whatever reason you spot something to fix but cannot patch it yourself, please
<a href="https://github.com/rails/rails/issues">open an issue</a>.
</p>
<p>And last but not least, any kind of discussion regarding Ruby on Rails
documentation is very welcome on the <a href="https://groups.google.com/forum/#!forum/rubyonrails-docs">rubyonrails-docs mailing list</a>.
</p>
</div>
</div>
</div>
<hr class="hide" />
<div id="footer">
<div class="wrapper">
<p>This work is licensed under a <a href="https://creativecommons.org/licenses/by-sa/4.0/">Creative Commons Attribution-ShareAlike 4.0 International</a> License</p>
<p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
</div>
</div>
</body>
</html>