-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupgrading_ruby_on_rails.html
1887 lines (1693 loc) · 136 KB
/
upgrading_ruby_on_rails.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
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Upgrading Ruby on Rails — 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>
<meta property="og:title" content="Upgrading Ruby on Rails — Ruby on Rails Guides" />
<meta name="description" content="Upgrading Ruby on RailsThis guide provides steps to be followed when you upgrade your applications to a newer version of Ruby on Rails. These steps are also available in individual release guides." />
<meta property="og:description" content="Upgrading Ruby on RailsThis guide provides steps to be followed when you upgrade your applications to a newer version of Ruby on Rails. These steps are also available in individual release guides." />
<meta property="og:locale" content="en_US" />
<meta property="og:site_name" content="Ruby on Rails Guides" />
<meta property="og:image" content="https://avatars.githubusercontent.com/u/4223" />
<meta property="og:type" content="website" />
</head>
<body class="guide">
<div id="topNav">
<div class="wrapper">
<strong class="more-info-label">공식 웹사이트 <a href="https://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="https://weblog.rubyonrails.org/">블로그</a></li>
<li class="more-info"><a href="https://guides.rubyonrails.org/">영문가이드</a></li>
<li class="more-info"><a href="https://api.rubyonrails.org/">레일스API</a></li>
<li class="more-info"><a href="https://stackoverflow.com/questions/tagged/ruby-on-rails">질문하기</a></li>
<li class="more-info"><a href="https://github.com/rails/rails">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">홈</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 />
<div class="guides-section-container">
<div class="guides-section">
<dt>시작하면서</dt>
<dd><a href="getting_started.html">레일스로 시작하기</a></dd>
</div>
<div class="guides-section">
<dt>모델</dt>
<dd><a href="active_record_basics.html">액티브 레코드 기본</a></dd>
<dd><a href="active_record_migrations.html">액티브 레코드 마이그레이션</a></dd>
<dd><a href="active_record_validations.html">액티브 레코드 유효성 검증</a></dd>
<dd><a href="active_record_callbacks.html">액티브 레코드 콜백</a></dd>
<dd><a href="association_basics.html">Active Record Associations</a></dd>
<dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
</div>
<div class="guides-section">
<dt>Views</dt>
<dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
<dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
</div>
<div class="guides-section">
<dt>Controllers</dt>
<dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
<dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
</div>
<div class="guides-section">
<dt>Other Components</dt>
<dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
<dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
<dd><a href="active_job_basics.html">Active Job Basics</a></dd>
<dd><a href="active_storage_overview.html">Active Storage Overview</a></dd>
<dd><a href="action_cable_overview.html">Action Cable Overview</a></dd>
</div>
<div class="guides-section">
<dt>Digging Deeper</dt>
<dd><a href="i18n.html">Rails Internationalization (I18n) API</a></dd>
<dd><a href="testing.html">Testing Rails Applications</a></dd>
<dd><a href="security.html">Securing Rails Applications</a></dd>
<dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
<dd><a href="configuring.html">Configuring Rails Applications</a></dd>
<dd><a href="command_line.html">The Rails Command Line</a></dd>
<dd><a href="asset_pipeline.html">The Asset Pipeline</a></dd>
<dd><a href="working_with_javascript_in_rails.html">Working with JavaScript in Rails</a></dd>
<dd><a href="autoloading_and_reloading_constants.html">Autoloading and Reloading Constants (Zeitwerk Mode)</a></dd>
<dd><a href="autoloading_and_reloading_constants_classic_mode.html">Autoloading and Reloading Constants (Classic Mode)</a></dd>
<dd><a href="caching_with_rails.html">Caching with Rails: An Overview</a></dd>
<dd><a href="api_app.html">Using Rails for API-only Applications</a></dd>
</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="6_0_release_notes.html">Version 6.0 - August 2019</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">기여하기</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">레일스로 시작하기</option>
</optgroup>
<optgroup label="모델">
<option value="active_record_basics.html">액티브 레코드 기본</option>
<option value="active_record_migrations.html">액티브 레코드 마이그레이션</option>
<option value="active_record_validations.html">액티브 레코드 유효성 검증</option>
<option value="active_record_callbacks.html">액티브 레코드 콜백</option>
<option value="association_basics.html">Active Record Associations</option>
<option value="active_record_querying.html">Active Record Query Interface</option>
</optgroup>
<optgroup label="Views">
<option value="layouts_and_rendering.html">Layouts and Rendering in Rails</option>
<option value="form_helpers.html">Action View Form Helpers</option>
</optgroup>
<optgroup label="Controllers">
<option value="action_controller_overview.html">Action Controller Overview</option>
<option value="routing.html">Rails Routing from the Outside In</option>
</optgroup>
<optgroup label="Other Components">
<option value="active_support_core_extensions.html">Active Support Core Extensions</option>
<option value="action_mailer_basics.html">Action Mailer Basics</option>
<option value="active_job_basics.html">Active Job Basics</option>
<option value="active_storage_overview.html">Active Storage Overview</option>
<option value="action_cable_overview.html">Action Cable Overview</option>
</optgroup>
<optgroup label="Digging Deeper">
<option value="i18n.html">Rails Internationalization (I18n) API</option>
<option value="testing.html">Testing Rails Applications</option>
<option value="security.html">Securing Rails Applications</option>
<option value="debugging_rails_applications.html">Debugging Rails Applications</option>
<option value="configuring.html">Configuring Rails Applications</option>
<option value="command_line.html">The Rails Command Line</option>
<option value="asset_pipeline.html">The Asset Pipeline</option>
<option value="working_with_javascript_in_rails.html">Working with JavaScript in Rails</option>
<option value="autoloading_and_reloading_constants.html">Autoloading and Reloading Constants (Zeitwerk Mode)</option>
<option value="autoloading_and_reloading_constants_classic_mode.html">Autoloading and Reloading Constants (Classic Mode)</option>
<option value="caching_with_rails.html">Caching with Rails: An Overview</option>
<option value="api_app.html">Using Rails for API-only Applications</option>
</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="6_0_release_notes.html">Version 6.0 - August 2019</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>Upgrading Ruby on Rails</h2><p>This guide provides steps to be followed when you upgrade your applications to a newer version of Ruby on Rails. These steps are also available in individual release guides.</p>
<div id="subCol">
<h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
<ol class="chapters">
<li>
<a href="#general-advice">General Advice</a>
<ul>
<li><a href="#test-coverage">Test Coverage</a></li>
<li><a href="#the-upgrade-process">The Upgrade Process</a></li>
<li><a href="#ruby-versions">Ruby Versions</a></li>
<li><a href="#the-update-task">The Update Task</a></li>
<li><a href="#configure-framework-defaults">Configure Framework Defaults</a></li>
</ul>
</li>
<li>
<a href="#upgrading-from-rails-5-2-to-rails-6-0">Upgrading from Rails 5.2 to Rails 6.0</a>
<ul>
<li><a href="#using-webpacker">Using Webpacker</a></li>
<li><a href="#force-ssl">Force SSL</a></li>
<li><a href="#purpose-in-signed-or-encrypted-cookie-is-now-embedded-within-cookies">Purpose in signed or encrypted cookie is now embedded within cookies</a></li>
<li><a href="#all-npm-packages-have-been-moved-to-the-@rails-scope">All npm packages have been moved to the <code>@rails</code> scope</a></li>
<li><a href="#action-cable-javascript-api-changes">Action Cable JavaScript API Changes</a></li>
<li><a href="#actiondispatch-response-content-type-now-returned-content-type-header-as-it-is"><code>ActionDispatch::Response#content_type</code> now returned Content-Type header as it is.</a></li>
<li><a href="#autoloading">Autoloading</a></li>
<li><a href="#active-storage-assignment-behavior-change">Active Storage assignment behavior change</a></li>
</ul>
</li>
<li>
<a href="#upgrading-from-rails-5-1-to-rails-5-2">Upgrading from Rails 5.1 to Rails 5.2</a>
<ul>
<li><a href="#upgrading-from-rails-5-1-to-rails-5-2-bootsnap">Bootsnap</a></li>
<li><a href="#expiry-in-signed-or-encrypted-cookie-is-now-embedded-in-the-cookies-values">Expiry in signed or encrypted cookie is now embedded in the cookies values</a></li>
</ul>
</li>
<li>
<a href="#upgrading-from-rails-5-0-to-rails-5-1">Upgrading from Rails 5.0 to Rails 5.1</a>
<ul>
<li><a href="#top-level-hashwithindifferentaccess-is-soft-deprecated">Top-level <code>HashWithIndifferentAccess</code> is soft-deprecated</a></li>
<li><a href="#application-secrets-now-loaded-with-all-keys-as-symbols"><code>application.secrets</code> now loaded with all keys as symbols</a></li>
<li><a href="#removed-deprecated-support-to-text-and-nothing-in-render">Removed deprecated support to <code>:text</code> and <code>:nothing</code> in <code>render</code></a></li>
</ul>
</li>
<li>
<a href="#upgrading-from-rails-4-2-to-rails-5-0">Upgrading from Rails 4.2 to Rails 5.0</a>
<ul>
<li><a href="#ruby-2-2-2-required">Ruby 2.2.2+ required</a></li>
<li><a href="#active-record-models-now-inherit-from-applicationrecord-by-default">Active Record Models Now Inherit from ApplicationRecord by Default</a></li>
<li><a href="#halting-callback-chains-via-throw-abort">Halting Callback Chains via <code>throw(:abort)</code></a></li>
<li><a href="#activejob-now-inherits-from-applicationjob-by-default">ActiveJob Now Inherits from ApplicationJob by Default</a></li>
<li><a href="#rails-controller-testing">Rails Controller Testing</a></li>
<li><a href="#autoloading-is-disabled-after-booting-in-the-production-environment">Autoloading is Disabled After Booting in the Production Environment</a></li>
<li><a href="#xml-serialization">XML Serialization</a></li>
<li><a href="#removed-support-for-legacy-mysql-database-adapter">Removed Support for Legacy <code>mysql</code> Database Adapter</a></li>
<li><a href="#removed-support-for-debugger">Removed Support for Debugger</a></li>
<li><a href="#use-rails-for-running-tasks-and-tests">Use <code>rails</code> for running tasks and tests</a></li>
<li><a href="#actioncontroller-parameters-no-longer-inherits-from-hashwithindifferentaccess"><code>ActionController::Parameters</code> No Longer Inherits from <code>HashWithIndifferentAccess</code></a></li>
<li><a href="#protect-from-forgery-now-defaults-to-prepend-false"><code>protect_from_forgery</code> Now Defaults to <code>prepend: false</code></a></li>
<li><a href="#default-template-handler-is-now-raw">Default Template Handler is Now RAW</a></li>
<li><a href="#added-wildcard-matching-for-template-dependencies">Added Wildcard Matching for Template Dependencies</a></li>
<li><a href="#actionview-helpers-recordtaghelper-moved-to-external-gem-record-tag-helper"><code>ActionView::Helpers::RecordTagHelper</code> moved to external gem (record_tag_helper)</a></li>
<li><a href="#removed-support-for-protected-attributes-gem">Removed Support for <code>protected_attributes</code> Gem</a></li>
<li><a href="#removed-support-for-activerecord-deprecated-finders-gem">Removed support for <code>activerecord-deprecated_finders</code> gem</a></li>
<li><a href="#activesupport-testcase-default-test-order-is-now-random"><code>ActiveSupport::TestCase</code> Default Test Order is Now Random</a></li>
<li><a href="#actioncontroller-live-became-a-concern"><code>ActionController::Live</code> became a <code>Concern</code></a></li>
<li><a href="#new-framework-defaults">New Framework Defaults</a></li>
<li><a href="#changes-with-json-jsonb-serialization">Changes with JSON/JSONB serialization</a></li>
</ul>
</li>
<li>
<a href="#upgrading-from-rails-4-1-to-rails-4-2">Upgrading from Rails 4.1 to Rails 4.2</a>
<ul>
<li><a href="#web-console">Web Console</a></li>
<li><a href="#responders">Responders</a></li>
<li><a href="#error-handling-in-transaction-callbacks">Error handling in transaction callbacks</a></li>
<li><a href="#ordering-of-test-cases">Ordering of test cases</a></li>
<li><a href="#serialized-attributes">Serialized attributes</a></li>
<li><a href="#production-log-level">Production log level</a></li>
<li><a href="#after-bundle-in-rails-templates"><code>after_bundle</code> in Rails templates</a></li>
<li><a href="#rails-html-sanitizer">Rails HTML Sanitizer</a></li>
<li><a href="#rails-dom-testing">Rails DOM Testing</a></li>
<li><a href="#masked-authenticity-tokens">Masked Authenticity Tokens</a></li>
<li><a href="#action-mailer">Action Mailer</a></li>
<li><a href="#foreign-key-support">Foreign Key Support</a></li>
</ul>
</li>
<li>
<a href="#upgrading-from-rails-4-0-to-rails-4-1">Upgrading from Rails 4.0 to Rails 4.1</a>
<ul>
<li><a href="#csrf-protection-from-remote-script-tags">CSRF protection from remote <code><script></code> tags</a></li>
<li><a href="#spring">Spring</a></li>
<li><a href="#config-secrets-yml"><code>config/secrets.yml</code></a></li>
<li><a href="#changes-to-test-helper">Changes to test helper</a></li>
<li><a href="#cookies-serializer">Cookies serializer</a></li>
<li><a href="#flash-structure-changes">Flash structure changes</a></li>
<li><a href="#changes-in-json-handling">Changes in JSON handling</a></li>
<li><a href="#usage-of-return-within-inline-callback-blocks">Usage of <code>return</code> within inline callback blocks</a></li>
<li><a href="#methods-defined-in-active-record-fixtures">Methods defined in Active Record fixtures</a></li>
<li><a href="#i18n-enforcing-available-locales">I18n enforcing available locales</a></li>
<li><a href="#mutator-methods-called-on-relation">Mutator methods called on Relation</a></li>
<li><a href="#changes-on-default-scopes">Changes on Default Scopes</a></li>
<li><a href="#rendering-content-from-string">Rendering content from string</a></li>
<li><a href="#postgresql-json-and-hstore-datatypes">PostgreSQL json and hstore datatypes</a></li>
<li><a href="#explicit-block-use-for-activesupport-callbacks">Explicit block use for <code>ActiveSupport::Callbacks</code></a></li>
</ul>
</li>
<li>
<a href="#upgrading-from-rails-3-2-to-rails-4-0">Upgrading from Rails 3.2 to Rails 4.0</a>
<ul>
<li><a href="#http-patch">HTTP PATCH</a></li>
<li><a href="#upgrading-from-rails-3-2-to-rails-4-0-gemfile">Gemfile</a></li>
<li><a href="#upgrading-from-rails-3-2-to-rails-4-0-vendor-plugins">vendor/plugins</a></li>
<li><a href="#upgrading-from-rails-3-2-to-rails-4-0-active-record">Active Record</a></li>
<li><a href="#active-resource">Active Resource</a></li>
<li><a href="#active-model">Active Model</a></li>
<li><a href="#action-pack">Action Pack</a></li>
<li><a href="#active-support">Active Support</a></li>
<li><a href="#helpers-loading-order">Helpers Loading Order</a></li>
<li><a href="#active-record-observer-and-action-controller-sweeper">Active Record Observer and Action Controller Sweeper</a></li>
<li><a href="#sprockets-rails">sprockets-rails</a></li>
<li><a href="#sass-rails">sass-rails</a></li>
</ul>
</li>
<li>
<a href="#upgrading-from-rails-3-1-to-rails-3-2">Upgrading from Rails 3.1 to Rails 3.2</a>
<ul>
<li><a href="#upgrading-from-rails-3-1-to-rails-3-2-gemfile">Gemfile</a></li>
<li><a href="#upgrading-from-rails-3-1-to-rails-3-2-config-environments-development-rb">config/environments/development.rb</a></li>
<li><a href="#upgrading-from-rails-3-1-to-rails-3-2-config-environments-test-rb">config/environments/test.rb</a></li>
<li><a href="#upgrading-from-rails-3-1-to-rails-3-2-vendor-plugins">vendor/plugins</a></li>
<li><a href="#upgrading-from-rails-3-1-to-rails-3-2-active-record">Active Record</a></li>
</ul>
</li>
<li>
<a href="#upgrading-from-rails-3-0-to-rails-3-1">Upgrading from Rails 3.0 to Rails 3.1</a>
<ul>
<li><a href="#gemfile">Gemfile</a></li>
<li><a href="#config-application-rb">config/application.rb</a></li>
<li><a href="#upgrading-from-rails-3-0-to-rails-3-1-config-environments-development-rb">config/environments/development.rb</a></li>
<li><a href="#config-environments-production-rb">config/environments/production.rb</a></li>
<li><a href="#upgrading-from-rails-3-0-to-rails-3-1-config-environments-test-rb">config/environments/test.rb</a></li>
<li><a href="#config-initializers-wrap-parameters-rb">config/initializers/wrap_parameters.rb</a></li>
<li><a href="#config-initializers-session-store-rb">config/initializers/session_store.rb</a></li>
<li><a href="#remove-cache-and-concat-options-in-asset-helpers-references-in-views">Remove :cache and :concat options in asset helpers references in views</a></li>
</ul>
</li>
</ol>
</div>
</div>
</div>
<div id="container">
<div class="wrapper">
<div id="mainCol">
<h3 id="general-advice"><a class="anchorlink" href="#general-advice">1 General Advice</a></h3><p>Before attempting to upgrade an existing application, you should be sure you have a good reason to upgrade. You need to balance several factors: the need for new features, the increasing difficulty of finding support for old code, and your available time and skills, to name a few.</p><h4 id="test-coverage"><a class="anchorlink" href="#test-coverage">1.1 Test Coverage</a></h4><p>The best way to be sure that your application still works after upgrading is to have good test coverage before you start the process. If you don't have automated tests that exercise the bulk of your application, you'll need to spend time manually exercising all the parts that have changed. In the case of a Rails upgrade, that will mean every single piece of functionality in the application. Do yourself a favor and make sure your test coverage is good <em>before</em> you start an upgrade.</p><h4 id="the-upgrade-process"><a class="anchorlink" href="#the-upgrade-process">1.2 The Upgrade Process</a></h4><p>When changing Rails versions, it's best to move slowly, one minor version at a time, in order to make good use of the deprecation warnings. Rails version numbers are in the form Major.Minor.Patch. Major and Minor versions are allowed to make changes to the public API, so this may cause errors in your application. Patch versions only include bug fixes, and don't change any public API.</p><p>The process should go as follows:</p>
<ol>
<li>Write tests and make sure they pass.</li>
<li>Move to the latest patch version after your current version.</li>
<li>Fix tests and deprecated features.</li>
<li>Move to the latest patch version of the next minor version.</li>
</ol>
<p>Repeat this process until you reach your target Rails version. Each time you move versions, you will need to change the Rails version number in the <code>Gemfile</code> (and possibly other gem versions) and run <code>bundle update</code>. Then run the Update task mentioned below to update configuration files, then run your tests.</p><p>You can find a list of all released Rails versions <a href="https://rubygems.org/gems/rails/versions">here</a>.</p><h4 id="ruby-versions"><a class="anchorlink" href="#ruby-versions">1.3 Ruby Versions</a></h4><p>Rails generally stays close to the latest released Ruby version when it's released:</p>
<ul>
<li>Rails 6 requires Ruby 2.5.0 or newer.</li>
<li>Rails 5 requires Ruby 2.2.2 or newer.</li>
<li>Rails 4 prefers Ruby 2.0 and requires 1.9.3 or newer.</li>
<li>Rails 3.2.x is the last branch to support Ruby 1.8.7.</li>
<li>Rails 3 and above require Ruby 1.8.7 or higher. Support for all of the previous Ruby versions has been dropped officially. You should upgrade as early as possible.</li>
</ul>
<div class="info"><p>Ruby 1.8.7 p248 and p249 have marshalling bugs that crash Rails. Ruby Enterprise Edition has these fixed since the release of 1.8.7-2010.02. On the 1.9 front, Ruby 1.9.1 is not usable because it outright segfaults, so if you want to use 1.9.x, jump straight to 1.9.3 for smooth sailing.</p></div><h4 id="the-update-task"><a class="anchorlink" href="#the-update-task">1.4 The Update Task</a></h4><p>Rails provides the <code>app:update</code> command (<code>rake rails:update</code> on 4.2 and earlier). After updating the Rails version
in the <code>Gemfile</code>, run this command.
This will help you with the creation of new files and changes of old files in an
interactive session.</p><div class="code_container">
<pre class="brush: plain; gutter: false; toolbar: false">
$ rails app:update
identical config/boot.rb
exist config
conflict config/routes.rb
Overwrite /myapp/config/routes.rb? (enter "h" for help) [Ynaqdh]
force config/routes.rb
conflict config/application.rb
Overwrite /myapp/config/application.rb? (enter "h" for help) [Ynaqdh]
force config/application.rb
conflict config/environment.rb
...
</pre>
</div>
<p>Don't forget to review the difference, to see if there were any unexpected changes.</p><h4 id="configure-framework-defaults"><a class="anchorlink" href="#configure-framework-defaults">1.5 Configure Framework Defaults</a></h4><p>The new Rails version might have different configuration defaults than the previous version. However, after following the steps described above, your application would still run with configuration defaults from the <em>previous</em> Rails version. That's because the value for <code>config.load_defaults</code> in <code>config/application.rb</code> has not been changed yet.</p><p>To allow you to upgrade to new defaults one by one, the update task has created a file <code>config/initializers/new_framework_defaults.rb</code>. Once your application is ready to run with new defaults, you can remove this file and flip the <code>config.load_defaults</code> value.</p><h3 id="upgrading-from-rails-5-2-to-rails-6-0"><a class="anchorlink" href="#upgrading-from-rails-5-2-to-rails-6-0">2 Upgrading from Rails 5.2 to Rails 6.0</a></h3><p>For more information on changes made to Rails 6.0 please see the <a href="6_0_release_notes.html">release notes</a>.</p><h4 id="using-webpacker"><a class="anchorlink" href="#using-webpacker">2.1 Using Webpacker</a></h4><p><a href="https://github.com/rails/webpacker">Webpacker</a>
is the default JavaScript compiler for Rails 6. But if you are upgrading the app, it is not activated by default.
If you want to use Webpacker, then include it in your Gemfile and install it:</p><div class="code_container">
<pre class="brush: ruby; gutter: false; toolbar: false">
gem "webpacker"
</pre>
</div>
<div class="code_container">
<pre class="brush: plain; gutter: false; toolbar: false">
bin/rails webpacker:install
</pre>
</div>
<h4 id="force-ssl"><a class="anchorlink" href="#force-ssl">2.2 Force SSL</a></h4><p>The <code>force_ssl</code> method on controllers has been deprecated and will be removed in
Rails 6.1. You are encouraged to enable <code>config.force_ssl</code> to enforce HTTPS
connections throughout your application. If you need to exempt certain endpoints
from redirection, you can use <code>config.ssl_options</code> to configure that behavior.</p><h4 id="purpose-in-signed-or-encrypted-cookie-is-now-embedded-within-cookies"><a class="anchorlink" href="#purpose-in-signed-or-encrypted-cookie-is-now-embedded-within-cookies">2.3 Purpose in signed or encrypted cookie is now embedded within cookies</a></h4><p>To improve security, Rails embeds the purpose information in encrypted or signed cookies value.
Rails can then thwart attacks that attempt to copy the signed/encrypted value
of a cookie and use it as the value of another cookie.</p><p>This new embed information make those cookies incompatible with versions of Rails older than 6.0.</p><p>If you require your cookies to be read by Rails 5.2 and older, or you are still validating your 6.0 deploy and want
to be able to rollback set
<code>Rails.application.config.action_dispatch.use_cookies_with_metadata</code> to <code>false</code>.</p><h4 id="all-npm-packages-have-been-moved-to-the-@rails-scope"><a class="anchorlink" href="#all-npm-packages-have-been-moved-to-the-@rails-scope">2.4 All npm packages have been moved to the <code>@rails</code> scope</a></h4><p>If you were previously loading any of the <code>actioncable</code>, <code>activestorage</code>,
or <code>rails-ujs</code> packages through npm/yarn, you must update the names of these
dependencies before you can upgrade them to <code>6.0.0</code>:</p><div class="code_container">
<pre class="brush: plain; gutter: false; toolbar: false">
actioncable → @rails/actioncable
activestorage → @rails/activestorage
rails-ujs → @rails/ujs
</pre>
</div>
<h4 id="action-cable-javascript-api-changes"><a class="anchorlink" href="#action-cable-javascript-api-changes">2.5 Action Cable JavaScript API Changes</a></h4><p>The Action Cable JavaScript package has been converted from CoffeeScript
to ES2015, and we now publish the source code in the npm distribution.</p><p>This release includes some breaking changes to optional parts of the
Action Cable JavaScript API:</p>
<ul>
<li>Configuration of the WebSocket adapter and logger adapter have been moved
from properties of <code>ActionCable</code> to properties of <code>ActionCable.adapters</code>.
If you are configuring these adapters you will need to make
these changes:</li>
</ul>
<div class="code_container">
<pre class="brush: plain; gutter: false; toolbar: false">
- ActionCable.WebSocket = MyWebSocket
+ ActionCable.adapters.WebSocket = MyWebSocket
</pre>
</div>
<div class="code_container">
<pre class="brush: plain; gutter: false; toolbar: false">
- ActionCable.logger = myLogger
+ ActionCable.adapters.logger = myLogger
</pre>
</div>
<ul>
<li>The <code>ActionCable.startDebugging()</code> and <code>ActionCable.stopDebugging()</code>
methods have been removed and replaced with the property
<code>ActionCable.logger.enabled</code>. If you are using these methods you
will need to make these changes:</li>
</ul>
<div class="code_container">
<pre class="brush: plain; gutter: false; toolbar: false">
- ActionCable.startDebugging()
+ ActionCable.logger.enabled = true
</pre>
</div>
<div class="code_container">
<pre class="brush: plain; gutter: false; toolbar: false">
- ActionCable.stopDebugging()
+ ActionCable.logger.enabled = false
</pre>
</div>
<h4 id="actiondispatch-response-content-type-now-returned-content-type-header-as-it-is"><a class="anchorlink" href="#actiondispatch-response-content-type-now-returned-content-type-header-as-it-is">2.6 <code>ActionDispatch::Response#content_type</code> now returned Content-Type header as it is.</a></h4><p>Previously, <code>ActionDispatch::Response#content_type</code> returned value does NOT contain charset part.
This behavior changed to returned Content-Type header containing charset part as it is.</p><p>If you want just MIME type, please use <code>ActionDispatch::Response#media_type</code> instead.</p><p>Before:</p><div class="code_container">
<pre class="brush: ruby; gutter: false; toolbar: false">
resp = ActionDispatch::Response.new(200, "Content-Type" => "text/csv; header=present; charset=utf-16")
resp.content_type #=> "text/csv; header=present"
</pre>
</div>
<p>After:</p><div class="code_container">
<pre class="brush: ruby; gutter: false; toolbar: false">
resp = ActionDispatch::Response.new(200, "Content-Type" => "text/csv; header=present; charset=utf-16")
resp.content_type #=> "text/csv; header=present; charset=utf-16"
resp.media_type #=> "text/csv"
</pre>
</div>
<h4 id="autoloading"><a class="anchorlink" href="#autoloading">2.7 Autoloading</a></h4><p>The default configuration for Rails 6</p><div class="code_container">
<pre class="brush: ruby; gutter: false; toolbar: false">
# config/application.rb
config.load_defaults "6.0"
</pre>
</div>
<p>enables <code>zeitwerk</code> autoloading mode on CRuby. In that mode, autoloading, reloading, and eager loading are managed by <a href="https://github.com/fxn/zeitwerk">Zeitwerk</a>.</p><h5 id="public-api"><a class="anchorlink" href="#public-api">2.7.1 Public API</a></h5><p>In general, applications do not need to use the API of Zeitwerk directly. Rails sets things up according to the existing contract: <code>config.autoload_paths</code>, <code>config.cache_classes</code>, etc.</p><p>While applications should stick to that interface, the actual Zeitwerk loader object can be accessed as</p><div class="code_container">
<pre class="brush: ruby; gutter: false; toolbar: false">
Rails.autoloaders.main
</pre>
</div>
<p>That may be handy if you need to preload STIs or configure a custom inflector, for example.</p><h5 id="project-structure"><a class="anchorlink" href="#project-structure">2.7.2 Project Structure</a></h5><p>If the application being upgraded autoloads correctly, the project structure should be already mostly compatible.</p><p>However, <code>classic</code> mode infers file names from missing constant names (<code>underscore</code>), whereas <code>zeitwerk</code> mode infers constant names from file names (<code>camelize</code>). These helpers are not always inverse of each other, in particular if acronyms are involved. For instance, <code>"FOO".underscore</code> is <code>"foo"</code>, but <code>"foo".camelize</code> is <code>"Foo"</code>, not <code>"FOO"</code>.</p><p>Compatibility can be checked with the <code>zeitwerk:check</code> task:</p><div class="code_container">
<pre class="brush: plain; gutter: false; toolbar: false">
$ bin/rails zeitwerk:check
Hold on, I am eager loading the application.
All is good!
</pre>
</div>
<h5 id="require-dependency"><a class="anchorlink" href="#require-dependency">2.7.3 require_dependency</a></h5><p>All known use cases of <code>require_dependency</code> have been eliminated, you should grep the project and delete them.</p><p>If your application has STIs, please check their section in the guide <a href="autoloading_and_reloading_constants.html#single-table-inheritance">Autoloading and Reloading Constants (Zeitwerk Mode)</a>.</p><h5 id="qualified-names-in-class-and-module-definitions"><a class="anchorlink" href="#qualified-names-in-class-and-module-definitions">2.7.4 Qualified names in class and module definitions</a></h5><p>You can now robustly use constant paths in class and module definitions:</p><div class="code_container">
<pre class="brush: ruby; gutter: false; toolbar: false">
# Autoloading in this class' body matches Ruby semantics now.
class Admin::UsersController < ApplicationController
# ...
end
</pre>
</div>
<p>A gotcha to be aware of is that, depending on the order of execution, the classic autoloader could sometimes be able to autoload <code>Foo::Wadus</code> in</p><div class="code_container">
<pre class="brush: ruby; gutter: false; toolbar: false">
class Foo::Bar
Wadus
end
</pre>
</div>
<p>That does not match Ruby semantics because <code>Foo</code> is not in the nesting, and won't work at all in <code>zeitwerk</code> mode. If you find such corner case you can use the qualified name <code>Foo::Wadus</code>:</p><div class="code_container">
<pre class="brush: ruby; gutter: false; toolbar: false">
class Foo::Bar
Foo::Wadus
end
</pre>
</div>
<p>or add <code>Foo</code> to the nesting:</p><div class="code_container">
<pre class="brush: ruby; gutter: false; toolbar: false">
module Foo
class Bar
Wadus
end
end
</pre>
</div>
<h5 id="concerns"><a class="anchorlink" href="#concerns">2.7.5 Concerns</a></h5><p>You can autoload and eager load from a standard structure like</p><div class="code_container">
<pre class="brush: plain; gutter: false; toolbar: false">
app/models
app/models/concerns
</pre>
</div>
<p>In that case, <code>app/models/concerns</code> is assumed to be a root directory (because it belongs to the autoload paths), and it is ignored as namespace. So, <code>app/models/concerns/foo.rb</code> should define <code>Foo</code>, not <code>Concerns::Foo</code>.</p><p>The <code>Concerns::</code> namespace worked with the classic autoloader as a side-effect of the implementation, but it was not really an intended behavior. An application using <code>Concerns::</code> needs to rename those classes and modules to be able to run in <code>zeitwerk</code> mode.</p><h5 id="having-app-in-the-autoload-paths"><a class="anchorlink" href="#having-app-in-the-autoload-paths">2.7.6 Having <code>app</code> in the autoload paths</a></h5><p>Some projects want something like <code>app/api/base.rb</code> to define <code>API::Base</code>, and add <code>app</code> to the autoload paths to accomplish that in <code>classic</code> mode. Since Rails adds all subdirectories of <code>app</code> to the autoload paths automatically, we have another situation in which there are nested root directories, so that setup no longer works. Similar principle we explained above with <code>concerns</code>.</p><p>If you want to keep that structure, you'll need to delete the subdirectory from the autoload paths in an initializer:</p><div class="code_container">
<pre class="brush: ruby; gutter: false; toolbar: false">
ActiveSupport::Dependencies.autoload_paths.delete("#{Rails.root}/app/api")
</pre>
</div>
<h5 id="autoloaded-constants-and-explicit-namespaces"><a class="anchorlink" href="#autoloaded-constants-and-explicit-namespaces">2.7.7 Autoloaded Constants and Explicit Namespaces</a></h5><p>If a namespace is defined in a file, as <code>Hotel</code> is here:</p><div class="code_container">
<pre class="brush: plain; gutter: false; toolbar: false">
app/models/hotel.rb # Defines Hotel.
app/models/hotel/pricing.rb # Defines Hotel::Pricing.
</pre>
</div>
<p>the <code>Hotel</code> constant has to be set using the <code>class</code> or <code>module</code> keywords. For example:</p><div class="code_container">
<pre class="brush: ruby; gutter: false; toolbar: false">
class Hotel
end
</pre>
</div>
<p>is good.</p><p>Alternatives like</p><div class="code_container">
<pre class="brush: ruby; gutter: false; toolbar: false">
Hotel = Class.new
</pre>
</div>
<p>or</p><div class="code_container">
<pre class="brush: ruby; gutter: false; toolbar: false">
Hotel = Struct.new
</pre>
</div>
<p>won't work, child objects like <code>Hotel::Pricing</code> won't be found.</p><p>This restriction only applies to explicit namespaces. Classes and modules not defining a namespace can be defined using those idioms.</p><h5 id="one-file-one-constant-at-the-same-top-level"><a class="anchorlink" href="#one-file-one-constant-at-the-same-top-level">2.7.8 One file, one constant (at the same top-level)</a></h5><p>In <code>classic</code> mode you could technically define several constants at the same top-level and have them all reloaded. For example, given</p><div class="code_container">
<pre class="brush: ruby; gutter: false; toolbar: false">
# app/models/foo.rb
class Foo
end
class Bar
end
</pre>
</div>
<p>while <code>Bar</code> could not be autoloaded, autoloading <code>Foo</code> would mark <code>Bar</code> as autoloaded too. This is not the case in <code>zeitwerk</code> mode, you need to move <code>Bar</code> to its own file <code>bar.rb</code>. One file, one constant.</p><p>This affects only to constants at the same top-level as in the example above. Inner classes and modules are fine. For example, consider</p><div class="code_container">
<pre class="brush: ruby; gutter: false; toolbar: false">
# app/models/foo.rb
class Foo
class InnerClass
end
end
</pre>
</div>
<p>If the application reloads <code>Foo</code>, it will reload <code>Foo::InnerClass</code> too.</p><h5 id="spring-and-the-test-environment"><a class="anchorlink" href="#spring-and-the-test-environment">2.7.9 Spring and the <code>test</code> Environment</a></h5><p>Spring reloads the application code if something changes. In the <code>test</code> environment you need to enable reloading for that to work:</p><div class="code_container">
<pre class="brush: ruby; gutter: false; toolbar: false">
# config/environments/test.rb
config.cache_classes = false
</pre>
</div>
<p>Otherwise you'll get this error:</p><div class="code_container">
<pre class="brush: plain; gutter: false; toolbar: false">
reloading is disabled because config.cache_classes is true
</pre>
</div>
<h5 id="autoloading-bootsnap"><a class="anchorlink" href="#autoloading-bootsnap">2.7.10 Bootsnap</a></h5><p>Bootsnap should be at least version 1.4.2.</p><p>In addition to that, Bootsnap needs to disable the iseq cache due to a bug in the interpreter if running Ruby 2.5. Please make sure to depend on at least Bootsnap 1.4.4 in that case.</p><h5 id="config-add-autoload-paths-to-load-path"><a class="anchorlink" href="#config-add-autoload-paths-to-load-path">2.7.11 <code>config.add_autoload_paths_to_load_path</code></a></h5><p>The new configuration point</p><div class="code_container">
<pre class="brush: ruby; gutter: false; toolbar: false">
config.add_autoload_paths_to_load_path
</pre>
</div>
<p>is <code>true</code> by default for backwards compatibility, but allows you to opt-out from adding the autoload paths to <code>$LOAD_PATH</code>.</p><p>This makes sense in most applications, since you never should require a file in <code>app/models</code>, for example, and Zeitwerk only uses absolute file names internally.</p><p>By opting-out you optimize <code>$LOAD_PATH</code> lookups (less directories to check), and save Bootsnap work and memory consumption, since it does not need to build an index for these directories.</p><h5 id="thread-safety"><a class="anchorlink" href="#thread-safety">2.7.12 Thread-safety</a></h5><p>In classic mode, constant autoloading is not thread-safe, though Rails has locks in place for example to make web requests thread-safe when autoloading is enabled, as it is common in <code>development</code> mode.</p><p>Constant autoloading is thread-safe in <code>zeitwerk</code> mode. For example, you can now autoload in multi-threaded scripts executed by the <code>runner</code> command.</p><h5 id="globs-in-config-autoload-paths"><a class="anchorlink" href="#globs-in-config-autoload-paths">2.7.13 Globs in config.autoload_paths</a></h5><p>Beware of configurations like</p><div class="code_container">
<pre class="brush: ruby; gutter: false; toolbar: false">
config.autoload_paths += Dir["#{config.root}/lib/**/"]
</pre>
</div>
<p>Every element of <code>config.autoload_paths</code> should represent the top-level namespace (<code>Object</code>) and they cannot be nested in consequence (with the exception of <code>concerns</code> directories explained above).</p><p>To fix this, just remove the wildcards:</p><div class="code_container">
<pre class="brush: ruby; gutter: false; toolbar: false">
config.autoload_paths << "#{config.root}/lib"
</pre>
</div>
<h5 id="eager-loading-and-autoloading-are-consistent"><a class="anchorlink" href="#eager-loading-and-autoloading-are-consistent">2.7.14 Eager loading and autoloading are consistent</a></h5><p>In <code>classic</code> mode, if <code>app/models/foo.rb</code> defines <code>Bar</code>, you won't be able to autoload that file, but eager loading will work because it loads files recursively blindly. This can be a source of errors if you test things first eager loading, execution may fail later autoloading.</p><p>In <code>zeitwerk</code> mode both loading modes are consistent, they fail and err in the same files.</p><h5 id="how-to-use-the-classic-autoloader-in-rails-6"><a class="anchorlink" href="#how-to-use-the-classic-autoloader-in-rails-6">2.7.15 How to Use the Classic Autoloader in Rails 6</a></h5><p>Applications can load Rails 6 defaults and still use the classic autoloader by setting <code>config.autoloader</code> this way:</p><div class="code_container">
<pre class="brush: ruby; gutter: false; toolbar: false">
# config/application.rb
config.load_defaults "6.0"
config.autoloader = :classic
</pre>
</div>
<p>When using the Classic Autoloader in Rails 6 application it is recommended to set concurrency level to 1 in development environment, for the web servers and background processors, due to the thread-safety concerns.</p><h4 id="active-storage-assignment-behavior-change"><a class="anchorlink" href="#active-storage-assignment-behavior-change">2.8 Active Storage assignment behavior change</a></h4><p>In Rails 5.2, assigning to a collection of attachments declared with <code>has_many_attached</code> appended new files:</p><div class="code_container">
<pre class="brush: ruby; gutter: false; toolbar: false">
class User < ApplicationRecord
has_many_attached :highlights
end
user.highlights.attach(filename: "funky.jpg", ...)
user.higlights.count # => 1
blob = ActiveStorage::Blob.create_after_upload!(filename: "town.jpg", ...)
user.update!(highlights: [ blob ])
user.highlights.count # => 2
user.highlights.first.filename # => "funky.jpg"
user.highlights.second.filename # => "town.jpg"
</pre>
</div>
<p>With the default configuration for Rails 6.0, assigning to a collection of attachments replaces existing files
instead of appending to them. This matches Active Record behavior when assigning to a collection association:</p><div class="code_container">
<pre class="brush: ruby; gutter: false; toolbar: false">
user.highlights.attach(filename: "funky.jpg", ...)
user.highlights.count # => 1
blob = ActiveStorage::Blob.create_after_upload!(filename: "town.jpg", ...)
user.update!(highlights: [ blob ])
user.highlights.count # => 1
user.highlights.first.filename # => "town.jpg"
</pre>
</div>
<p><code>#attach</code> can be used to add new attachments without removing the existing ones:</p><div class="code_container">
<pre class="brush: ruby; gutter: false; toolbar: false">
blob = ActiveStorage::Blob.create_after_upload!(filename: "town.jpg", ...)
user.highlights.attach(blob)
user.highlights.count # => 2
user.highlights.first.filename # => "funky.jpg"
user.highlights.second.filename # => "town.jpg"
</pre>
</div>
<p>Opt in to the new default behavior by setting <code>config.active_storage.replace_on_assign_to_many</code> to <code>true</code>.
The old behavior will be deprecated in Rails 6.1 and removed in a subsequent release.</p><h3 id="upgrading-from-rails-5-1-to-rails-5-2"><a class="anchorlink" href="#upgrading-from-rails-5-1-to-rails-5-2">3 Upgrading from Rails 5.1 to Rails 5.2</a></h3><p>For more information on changes made to Rails 5.2 please see the <a href="5_2_release_notes.html">release notes</a>.</p><h4 id="upgrading-from-rails-5-1-to-rails-5-2-bootsnap"><a class="anchorlink" href="#upgrading-from-rails-5-1-to-rails-5-2-bootsnap">3.1 Bootsnap</a></h4><p>Rails 5.2 adds bootsnap gem in the <a href="https://github.com/rails/rails/pull/29313">newly generated app's Gemfile</a>.
The <code>app:update</code> command sets it up in <code>boot.rb</code>. If you want to use it, then add it in the Gemfile,
otherwise change the <code>boot.rb</code> to not use bootsnap.</p><h4 id="expiry-in-signed-or-encrypted-cookie-is-now-embedded-in-the-cookies-values"><a class="anchorlink" href="#expiry-in-signed-or-encrypted-cookie-is-now-embedded-in-the-cookies-values">3.2 Expiry in signed or encrypted cookie is now embedded in the cookies values</a></h4><p>To improve security, Rails now embeds the expiry information also in encrypted or signed cookies value.</p><p>This new embed information make those cookies incompatible with versions of Rails older than 5.2.</p><p>If you require your cookies to be read by 5.1 and older, or you are still validating your 5.2 deploy and want
to allow you to rollback set
<code>Rails.application.config.action_dispatch.use_authenticated_cookie_encryption</code> to <code>false</code>.</p><h3 id="upgrading-from-rails-5-0-to-rails-5-1"><a class="anchorlink" href="#upgrading-from-rails-5-0-to-rails-5-1">4 Upgrading from Rails 5.0 to Rails 5.1</a></h3><p>For more information on changes made to Rails 5.1 please see the <a href="5_1_release_notes.html">release notes</a>.</p><h4 id="top-level-hashwithindifferentaccess-is-soft-deprecated"><a class="anchorlink" href="#top-level-hashwithindifferentaccess-is-soft-deprecated">4.1 Top-level <code>HashWithIndifferentAccess</code> is soft-deprecated</a></h4><p>If your application uses the top-level <code>HashWithIndifferentAccess</code> class, you
should slowly move your code to instead use <code>ActiveSupport::HashWithIndifferentAccess</code>.</p><p>It is only soft-deprecated, which means that your code will not break at the
moment and no deprecation warning will be displayed, but this constant will be
removed in the future.</p><p>Also, if you have pretty old YAML documents containing dumps of such objects,
you may need to load and dump them again to make sure that they reference
the right constant, and that loading them won't break in the future.</p><h4 id="application-secrets-now-loaded-with-all-keys-as-symbols"><a class="anchorlink" href="#application-secrets-now-loaded-with-all-keys-as-symbols">4.2 <code>application.secrets</code> now loaded with all keys as symbols</a></h4><p>If your application stores nested configuration in <code>config/secrets.yml</code>, all keys
are now loaded as symbols, so access using strings should be changed.</p><p>From:</p><div class="code_container">
<pre class="brush: ruby; gutter: false; toolbar: false">
Rails.application.secrets[:smtp_settings]["address"]
</pre>
</div>
<p>To:</p><div class="code_container">
<pre class="brush: ruby; gutter: false; toolbar: false">
Rails.application.secrets[:smtp_settings][:address]
</pre>
</div>
<h4 id="removed-deprecated-support-to-text-and-nothing-in-render"><a class="anchorlink" href="#removed-deprecated-support-to-text-and-nothing-in-render">4.3 Removed deprecated support to <code>:text</code> and <code>:nothing</code> in <code>render</code></a></h4><p>If your views are using <code>render :text</code>, they will no longer work. The new method
of rendering text with MIME type of <code>text/plain</code> is to use <code>render :plain</code>.</p><p>Similarly, <code>render :nothing</code> is also removed and you should use the <code>head</code> method
to send responses that contain only headers. For example, <code>head :ok</code> sends a
200 response with no body to render.</p><h3 id="upgrading-from-rails-4-2-to-rails-5-0"><a class="anchorlink" href="#upgrading-from-rails-4-2-to-rails-5-0">5 Upgrading from Rails 4.2 to Rails 5.0</a></h3><p>For more information on changes made to Rails 5.0 please see the <a href="5_0_release_notes.html">release notes</a>.</p><h4 id="ruby-2-2-2-required"><a class="anchorlink" href="#ruby-2-2-2-required">5.1 Ruby 2.2.2+ required</a></h4><p>From Ruby on Rails 5.0 onwards, Ruby 2.2.2+ is the only supported Ruby version.
Make sure you are on Ruby 2.2.2 version or greater, before you proceed.</p><h4 id="active-record-models-now-inherit-from-applicationrecord-by-default"><a class="anchorlink" href="#active-record-models-now-inherit-from-applicationrecord-by-default">5.2 Active Record Models Now Inherit from ApplicationRecord by Default</a></h4><p>In Rails 4.2, an Active Record model inherits from <code>ActiveRecord::Base</code>. In Rails 5.0,
all models inherit from <code>ApplicationRecord</code>.</p><p><code>ApplicationRecord</code> is a new superclass for all app models, analogous to app
controllers subclassing <code>ApplicationController</code> instead of
<code>ActionController::Base</code>. This gives apps a single spot to configure app-wide
model behavior.</p><p>When upgrading from Rails 4.2 to Rails 5.0, you need to create an
<code>application_record.rb</code> file in <code>app/models/</code> and add the following content:</p><div class="code_container">
<pre class="brush: plain; gutter: false; toolbar: false">
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
</pre>
</div>
<p>Then make sure that all your models inherit from it.</p><h4 id="halting-callback-chains-via-throw-abort"><a class="anchorlink" href="#halting-callback-chains-via-throw-abort">5.3 Halting Callback Chains via <code>throw(:abort)</code></a></h4><p>In Rails 4.2, when a 'before' callback returns <code>false</code> in Active Record
and Active Model, then the entire callback chain is halted. In other words,
successive 'before' callbacks are not executed, and neither is the action wrapped
in callbacks.</p><p>In Rails 5.0, returning <code>false</code> in an Active Record or Active Model callback
will not have this side effect of halting the callback chain. Instead, callback
chains must be explicitly halted by calling <code>throw(:abort)</code>.</p><p>When you upgrade from Rails 4.2 to Rails 5.0, returning <code>false</code> in those kind of
callbacks will still halt the callback chain, but you will receive a deprecation
warning about this upcoming change.</p><p>When you are ready, you can opt into the new behavior and remove the deprecation
warning by adding the following configuration to your <code>config/application.rb</code>:</p><div class="code_container">
<pre class="brush: plain; gutter: false; toolbar: false">
ActiveSupport.halt_callback_chains_on_return_false = false
</pre>
</div>
<p>Note that this option will not affect Active Support callbacks since they never
halted the chain when any value was returned.</p><p>See <a href="https://github.com/rails/rails/pull/17227">#17227</a> for more details.</p><h4 id="activejob-now-inherits-from-applicationjob-by-default"><a class="anchorlink" href="#activejob-now-inherits-from-applicationjob-by-default">5.4 ActiveJob Now Inherits from ApplicationJob by Default</a></h4><p>In Rails 4.2, an Active Job inherits from <code>ActiveJob::Base</code>. In Rails 5.0, this
behavior has changed to now inherit from <code>ApplicationJob</code>.</p><p>When upgrading from Rails 4.2 to Rails 5.0, you need to create an
<code>application_job.rb</code> file in <code>app/jobs/</code> and add the following content:</p><div class="code_container">
<pre class="brush: plain; gutter: false; toolbar: false">
class ApplicationJob < ActiveJob::Base
end
</pre>
</div>
<p>Then make sure that all your job classes inherit from it.</p><p>See <a href="https://github.com/rails/rails/pull/19034">#19034</a> for more details.</p><h4 id="rails-controller-testing"><a class="anchorlink" href="#rails-controller-testing">5.5 Rails Controller Testing</a></h4><h5 id="extraction-of-some-helper-methods-to-rails-controller-testing"><a class="anchorlink" href="#extraction-of-some-helper-methods-to-rails-controller-testing">5.5.1 Extraction of some helper methods to <code>rails-controller-testing</code></a></h5><p><code>assigns</code> and <code>assert_template</code> have been extracted to the <code>rails-controller-testing</code> gem. To
continue using these methods in your controller tests, add <code>gem 'rails-controller-testing'</code> to
your <code>Gemfile</code>.</p><p>If you are using Rspec for testing, please see the extra configuration required in the gem's
documentation.</p><h5 id="new-behavior-when-uploading-files"><a class="anchorlink" href="#new-behavior-when-uploading-files">5.5.2 New behavior when uploading files</a></h5><p>If you are using <code>ActionDispatch::Http::UploadedFile</code> in your tests to
upload files, you will need to change to use the similar <code>Rack::Test::UploadedFile</code>
class instead.</p><p>See <a href="https://github.com/rails/rails/issues/26404">#26404</a> for more details.</p><h4 id="autoloading-is-disabled-after-booting-in-the-production-environment"><a class="anchorlink" href="#autoloading-is-disabled-after-booting-in-the-production-environment">5.6 Autoloading is Disabled After Booting in the Production Environment</a></h4><p>Autoloading is now disabled after booting in the production environment by
default.</p><p>Eager loading the application is part of the boot process, so top-level
constants are fine and are still autoloaded, no need to require their files.</p><p>Constants in deeper places only executed at runtime, like regular method bodies,
are also fine because the file defining them will have been eager loaded while booting.</p><p>For the vast majority of applications this change needs no action. But in the
very rare event that your application needs autoloading while running in
production mode, set <code>Rails.application.config.enable_dependency_loading</code> to
true.</p><h4 id="xml-serialization"><a class="anchorlink" href="#xml-serialization">5.7 XML Serialization</a></h4><p><code>ActiveModel::Serializers::Xml</code> has been extracted from Rails to the <code>activemodel-serializers-xml</code>
gem. To continue using XML serialization in your application, add <code>gem 'activemodel-serializers-xml'</code>
to your <code>Gemfile</code>.</p><h4 id="removed-support-for-legacy-mysql-database-adapter"><a class="anchorlink" href="#removed-support-for-legacy-mysql-database-adapter">5.8 Removed Support for Legacy <code>mysql</code> Database Adapter</a></h4><p>Rails 5 removes support for the legacy <code>mysql</code> database adapter. Most users should be able to
use <code>mysql2</code> instead. It will be converted to a separate gem when we find someone to maintain
it.</p><h4 id="removed-support-for-debugger"><a class="anchorlink" href="#removed-support-for-debugger">5.9 Removed Support for Debugger</a></h4><p><code>debugger</code> is not supported by Ruby 2.2 which is required by Rails 5. Use <code>byebug</code> instead.</p><h4 id="use-rails-for-running-tasks-and-tests"><a class="anchorlink" href="#use-rails-for-running-tasks-and-tests">5.10 Use <code>rails</code> for running tasks and tests</a></h4><p>Rails 5 adds the ability to run tasks and tests through <code>bin/rails</code> instead of rake. Generally
these changes are in parallel with rake, but some were ported over altogether. As the <code>rails</code>
command already looks for and runs <code>bin/rails</code>, we recommend you to use the shorter <code>rails</code>
over `bin/rails.</p><p>To use the new test runner simply type <code>rails test</code>.</p><p><code>rake dev:cache</code> is now <code>rails dev:cache</code>.</p><p>Run <code>rails</code> inside your application's directory to see the list of commands available.</p><h4 id="actioncontroller-parameters-no-longer-inherits-from-hashwithindifferentaccess"><a class="anchorlink" href="#actioncontroller-parameters-no-longer-inherits-from-hashwithindifferentaccess">5.11 <code>ActionController::Parameters</code> No Longer Inherits from <code>HashWithIndifferentAccess</code></a></h4><p>Calling <code>params</code> in your application will now return an object instead of a hash. If your
parameters are already permitted, then you will not need to make any changes. If you are using <code>map</code>
and other methods that depend on being able to read the hash regardless of <code>permitted?</code> you will
need to upgrade your application to first permit and then convert to a hash.</p><div class="code_container">
<pre class="brush: plain; gutter: false; toolbar: false">
params.permit([:proceed_to, :return_to]).to_h
</pre>
</div>
<h4 id="protect-from-forgery-now-defaults-to-prepend-false"><a class="anchorlink" href="#protect-from-forgery-now-defaults-to-prepend-false">5.12 <code>protect_from_forgery</code> Now Defaults to <code>prepend: false</code></a></h4><p><code>protect_from_forgery</code> defaults to <code>prepend: false</code> which means that it will be inserted into
the callback chain at the point in which you call it in your application. If you want
<code>protect_from_forgery</code> to always run first, then you should change your application to use
<code>protect_from_forgery prepend: true</code>.</p><h4 id="default-template-handler-is-now-raw"><a class="anchorlink" href="#default-template-handler-is-now-raw">5.13 Default Template Handler is Now RAW</a></h4><p>Files without a template handler in their extension will be rendered using the raw handler.
Previously Rails would render files using the ERB template handler.</p><p>If you do not want your file to be handled via the raw handler, you should add an extension
to your file that can be parsed by the appropriate template handler.</p><h4 id="added-wildcard-matching-for-template-dependencies"><a class="anchorlink" href="#added-wildcard-matching-for-template-dependencies">5.14 Added Wildcard Matching for Template Dependencies</a></h4><p>You can now use wildcard matching for your template dependencies. For example, if you were
defining your templates as such:</p><div class="code_container">
<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
<% # Template Dependency: recordings/threads/events/subscribers_changed %>
<% # Template Dependency: recordings/threads/events/completed %>
<% # Template Dependency: recordings/threads/events/uncompleted %>
</pre>
</div>
<p>You can now just call the dependency once with a wildcard.</p><div class="code_container">
<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
<% # Template Dependency: recordings/threads/events/* %>
</pre>
</div>
<h4 id="actionview-helpers-recordtaghelper-moved-to-external-gem-record-tag-helper"><a class="anchorlink" href="#actionview-helpers-recordtaghelper-moved-to-external-gem-record-tag-helper">5.15 <code>ActionView::Helpers::RecordTagHelper</code> moved to external gem (record_tag_helper)</a></h4><p><code>content_tag_for</code> and <code>div_for</code> have been removed in favor of just using <code>content_tag</code>. To continue using the older methods, add the <code>record_tag_helper</code> gem to your <code>Gemfile</code>:</p><div class="code_container">
<pre class="brush: ruby; gutter: false; toolbar: false">
gem 'record_tag_helper', '~> 1.0'
</pre>
</div>
<p>See <a href="https://github.com/rails/rails/pull/18411">#18411</a> for more details.</p><h4 id="removed-support-for-protected-attributes-gem"><a class="anchorlink" href="#removed-support-for-protected-attributes-gem">5.16 Removed Support for <code>protected_attributes</code> Gem</a></h4><p>The <code>protected_attributes</code> gem is no longer supported in Rails 5.</p><h4 id="removed-support-for-activerecord-deprecated-finders-gem"><a class="anchorlink" href="#removed-support-for-activerecord-deprecated-finders-gem">5.17 Removed support for <code>activerecord-deprecated_finders</code> gem</a></h4><p>The <code>activerecord-deprecated_finders</code> gem is no longer supported in Rails 5.</p><h4 id="activesupport-testcase-default-test-order-is-now-random"><a class="anchorlink" href="#activesupport-testcase-default-test-order-is-now-random">5.18 <code>ActiveSupport::TestCase</code> Default Test Order is Now Random</a></h4><p>When tests are run in your application, the default order is now <code>:random</code>
instead of <code>:sorted</code>. Use the following config option to set it back to <code>:sorted</code>.</p><div class="code_container">
<pre class="brush: ruby; gutter: false; toolbar: false">
# config/environments/test.rb
Rails.application.configure do
config.active_support.test_order = :sorted
end
</pre>
</div>
<h4 id="actioncontroller-live-became-a-concern"><a class="anchorlink" href="#actioncontroller-live-became-a-concern">5.19 <code>ActionController::Live</code> became a <code>Concern</code></a></h4><p>If you include <code>ActionController::Live</code> in another module that is included in your controller, then you
should also extend the module with <code>ActiveSupport::Concern</code>. Alternatively, you can use the <code>self.included</code> hook
to include <code>ActionController::Live</code> directly to the controller once the <code>StreamingSupport</code> is included.</p><p>This means that if your application used to have its own streaming module, the following code
would break in production mode:</p><div class="code_container">
<pre class="brush: ruby; gutter: false; toolbar: false">
# This is a work-around for streamed controllers performing authentication with Warden/Devise.
# See https://github.com/plataformatec/devise/issues/2332
# Authenticating in the router is another solution as suggested in that issue
class StreamingSupport
include ActionController::Live # this won't work in production for Rails 5
# extend ActiveSupport::Concern # unless you uncomment this line.
def process(name)
super(name)
rescue ArgumentError => e
if e.message == 'uncaught throw :warden'
throw :warden
else
raise e
end
end
end
</pre>
</div>
<h4 id="new-framework-defaults"><a class="anchorlink" href="#new-framework-defaults">5.20 New Framework Defaults</a></h4><h5 id="active-record-belongs-to-required-by-default-option"><a class="anchorlink" href="#active-record-belongs-to-required-by-default-option">5.20.1 Active Record <code>belongs_to</code> Required by Default Option</a></h5><p><code>belongs_to</code> will now trigger a validation error by default if the association is not present.</p><p>This can be turned off per-association with <code>optional: true</code>.</p><p>This default will be automatically configured in new applications. If existing application
want to add this feature it will need to be turned on in an initializer.</p><div class="code_container">
<pre class="brush: plain; gutter: false; toolbar: false">
config.active_record.belongs_to_required_by_default = true
</pre>
</div>
<h5 id="per-form-csrf-tokens"><a class="anchorlink" href="#per-form-csrf-tokens">5.20.2 Per-form CSRF Tokens</a></h5><p>Rails 5 now supports per-form CSRF tokens to mitigate against code-injection attacks with forms
created by JavaScript. With this option turned on, forms in your application will each have their
own CSRF token that is specific to the action and method for that form.</p><div class="code_container">
<pre class="brush: plain; gutter: false; toolbar: false">
config.action_controller.per_form_csrf_tokens = true
</pre>
</div>
<h5 id="forgery-protection-with-origin-check"><a class="anchorlink" href="#forgery-protection-with-origin-check">5.20.3 Forgery Protection with Origin Check</a></h5><p>You can now configure your application to check if the HTTP <code>Origin</code> header should be checked
against the site's origin as an additional CSRF defense. Set the following in your config to
true:</p><div class="code_container">
<pre class="brush: plain; gutter: false; toolbar: false">
config.action_controller.forgery_protection_origin_check = true
</pre>
</div>
<h5 id="allow-configuration-of-action-mailer-queue-name"><a class="anchorlink" href="#allow-configuration-of-action-mailer-queue-name">5.20.4 Allow Configuration of Action Mailer Queue Name</a></h5><p>The default mailer queue name is <code>mailers</code>. This configuration option allows you to globally change
the queue name. Set the following in your config:</p><div class="code_container">
<pre class="brush: plain; gutter: false; toolbar: false">
config.action_mailer.deliver_later_queue_name = :new_queue_name
</pre>
</div>
<h5 id="support-fragment-caching-in-action-mailer-views"><a class="anchorlink" href="#support-fragment-caching-in-action-mailer-views">5.20.5 Support Fragment Caching in Action Mailer Views</a></h5><p>Set <code>config.action_mailer.perform_caching</code> in your config to determine whether your Action Mailer views
should support caching.</p><div class="code_container">
<pre class="brush: plain; gutter: false; toolbar: false">
config.action_mailer.perform_caching = true
</pre>
</div>
<h5 id="configure-the-output-of-db-structure-dump"><a class="anchorlink" href="#configure-the-output-of-db-structure-dump">5.20.6 Configure the Output of <code>db:structure:dump</code></a></h5><p>If you're using <code>schema_search_path</code> or other PostgreSQL extensions, you can control how the schema is
dumped. Set to <code>:all</code> to generate all dumps, or to <code>:schema_search_path</code> to generate from schema search path.</p><div class="code_container">
<pre class="brush: plain; gutter: false; toolbar: false">
config.active_record.dump_schemas = :all
</pre>
</div>
<h5 id="configure-ssl-options-to-enable-hsts-with-subdomains"><a class="anchorlink" href="#configure-ssl-options-to-enable-hsts-with-subdomains">5.20.7 Configure SSL Options to Enable HSTS with Subdomains</a></h5><p>Set the following in your config to enable HSTS when using subdomains:</p><div class="code_container">
<pre class="brush: plain; gutter: false; toolbar: false">
config.ssl_options = { hsts: { subdomains: true } }
</pre>
</div>
<h5 id="preserve-timezone-of-the-receiver"><a class="anchorlink" href="#preserve-timezone-of-the-receiver">5.20.8 Preserve Timezone of the Receiver</a></h5><p>When using Ruby 2.4, you can preserve the timezone of the receiver when calling <code>to_time</code>.</p><div class="code_container">
<pre class="brush: plain; gutter: false; toolbar: false">
ActiveSupport.to_time_preserves_timezone = false
</pre>
</div>
<h4 id="changes-with-json-jsonb-serialization"><a class="anchorlink" href="#changes-with-json-jsonb-serialization">5.21 Changes with JSON/JSONB serialization</a></h4><p>In Rails 5.0, how JSON/JSONB attributes are serialized and deserialized changed. Now, if
you set a column equal to a <code>String</code>, Active Record will no longer turn that string
into a <code>Hash</code>, and will instead only return the string. This is not limited to code
interacting with models, but also affects <code>:default</code> column settings in <code>db/schema.rb</code>.
It is recommended that you do not set columns equal to a <code>String</code>, but pass a <code>Hash</code>
instead, which will be converted to and from a JSON string automatically.</p><h3 id="upgrading-from-rails-4-1-to-rails-4-2"><a class="anchorlink" href="#upgrading-from-rails-4-1-to-rails-4-2">6 Upgrading from Rails 4.1 to Rails 4.2</a></h3><h4 id="web-console"><a class="anchorlink" href="#web-console">6.1 Web Console</a></h4><p>First, add <code>gem 'web-console', '~> 2.0'</code> to the <code>:development</code> group in your <code>Gemfile</code> and run <code>bundle install</code> (it won't have been included when you upgraded Rails). Once it's been installed, you can simply drop a reference to the console helper (i.e., <code><%= console %></code>) into any view you want to enable it for. A console will also be provided on any error page you view in your development environment.</p><h4 id="responders"><a class="anchorlink" href="#responders">6.2 Responders</a></h4><p><code>respond_with</code> and the class-level <code>respond_to</code> methods have been extracted to the <code>responders</code> gem. To use them, simply add <code>gem 'responders', '~> 2.0'</code> to your <code>Gemfile</code>. Calls to <code>respond_with</code> and <code>respond_to</code> (again, at the class level) will no longer work without having included the <code>responders</code> gem in your dependencies:</p><div class="code_container">
<pre class="brush: ruby; gutter: false; toolbar: false">
# app/controllers/users_controller.rb
class UsersController < ApplicationController
respond_to :html, :json
def show
@user = User.find(params[:id])
respond_with @user
end
end
</pre>
</div>
<p>Instance-level <code>respond_to</code> is unaffected and does not require the additional gem:</p><div class="code_container">
<pre class="brush: ruby; gutter: false; toolbar: false">
# app/controllers/users_controller.rb
class UsersController < ApplicationController
def show
@user = User.find(params[:id])
respond_to do |format|
format.html
format.json { render json: @user }
end
end
end
</pre>
</div>
<p>See <a href="https://github.com/rails/rails/pull/16526">#16526</a> for more details.</p><h4 id="error-handling-in-transaction-callbacks"><a class="anchorlink" href="#error-handling-in-transaction-callbacks">6.3 Error handling in transaction callbacks</a></h4><p>Currently, Active Record suppresses errors raised
within <code>after_rollback</code> or <code>after_commit</code> callbacks and only prints them to
the logs. In the next version, these errors will no longer be suppressed.
Instead, the errors will propagate normally just like in other Active
Record callbacks.</p><p>When you define an <code>after_rollback</code> or <code>after_commit</code> callback, you
will receive a deprecation warning about this upcoming change. When
you are ready, you can opt into the new behavior and remove the
deprecation warning by adding following configuration to your
<code>config/application.rb</code>:</p><div class="code_container">
<pre class="brush: plain; gutter: false; toolbar: false">
config.active_record.raise_in_transactional_callbacks = true
</pre>
</div>
<p>See <a href="https://github.com/rails/rails/pull/14488">#14488</a> and
<a href="https://github.com/rails/rails/pull/16537">#16537</a> for more details.</p><h4 id="ordering-of-test-cases"><a class="anchorlink" href="#ordering-of-test-cases">6.4 Ordering of test cases</a></h4><p>In Rails 5.0, test cases will be executed in random order by default. In
anticipation of this change, Rails 4.2 introduced a new configuration option
<code>active_support.test_order</code> for explicitly specifying the test ordering. This
allows you to either lock down the current behavior by setting the option to
<code>:sorted</code>, or opt into the future behavior by setting the option to <code>:random</code>.</p><p>If you do not specify a value for this option, a deprecation warning will be
emitted. To avoid this, add the following line to your test environment:</p><div class="code_container">
<pre class="brush: ruby; gutter: false; toolbar: false">
# config/environments/test.rb
Rails.application.configure do
config.active_support.test_order = :sorted # or `:random` if you prefer
end
</pre>
</div>
<h4 id="serialized-attributes"><a class="anchorlink" href="#serialized-attributes">6.5 Serialized attributes</a></h4><p>When using a custom coder (e.g. <code>serialize :metadata, JSON</code>),
assigning <code>nil</code> to a serialized attribute will save it to the database
as <code>NULL</code> instead of passing the <code>nil</code> value through the coder (e.g. <code>"null"</code>
when using the <code>JSON</code> coder).</p><h4 id="production-log-level"><a class="anchorlink" href="#production-log-level">6.6 Production log level</a></h4><p>In Rails 5, the default log level for the production environment will be changed
to <code>:debug</code> (from <code>:info</code>). To preserve the current default, add the following
line to your <code>production.rb</code>:</p><div class="code_container">
<pre class="brush: ruby; gutter: false; toolbar: false">
# Set to `:info` to match the current default, or set to `:debug` to opt-into
# the future default.
config.log_level = :info
</pre>
</div>
<h4 id="after-bundle-in-rails-templates"><a class="anchorlink" href="#after-bundle-in-rails-templates">6.7 <code>after_bundle</code> in Rails templates</a></h4><p>If you have a Rails template that adds all the files in version control, it
fails to add the generated binstubs because it gets executed before Bundler:</p><div class="code_container">
<pre class="brush: ruby; gutter: false; toolbar: false">
# template.rb
generate(:scaffold, "person name:string")
route "root to: 'people#index'"
rake("db:migrate")
git :init
git add: "."