rails 4.2.0.beta3 → 4.2.0.beta4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -7
- data/guides/output/2_2_release_notes.html +724 -0
- data/guides/output/2_3_release_notes.html +870 -0
- data/guides/output/3_0_release_notes.html +773 -0
- data/guides/output/3_1_release_notes.html +740 -0
- data/guides/output/3_2_release_notes.html +797 -0
- data/guides/output/4_0_release_notes.html +523 -0
- data/guides/output/4_1_release_notes.html +806 -0
- data/guides/output/4_2_release_notes.html +728 -0
- data/guides/output/Gemfile +6 -0
- data/guides/output/_license.html +226 -0
- data/guides/output/_welcome.html +233 -0
- data/guides/output/action_controller_overview.html +1335 -0
- data/guides/output/action_mailer_basics.html +928 -0
- data/guides/output/action_view_overview.html +1509 -0
- data/guides/output/active_job_basics.html +546 -0
- data/guides/output/active_model_basics.html +438 -0
- data/guides/output/active_record_basics.html +594 -0
- data/guides/output/active_record_callbacks.html +592 -0
- data/guides/output/active_record_migrations.html +1123 -0
- data/guides/output/active_record_postgresql.html +675 -0
- data/guides/output/active_record_querying.html +1796 -0
- data/guides/output/active_record_validations.html +1301 -0
- data/guides/output/active_support_core_extensions.html +3450 -0
- data/guides/output/active_support_instrumentation.html +1121 -0
- data/guides/output/api_documentation_guidelines.html +498 -0
- data/guides/output/asset_pipeline.html +1167 -0
- data/guides/output/association_basics.html +2086 -0
- data/guides/output/caching_with_rails.html +553 -0
- data/guides/output/command_line.html +791 -0
- data/guides/output/configuring.html +1055 -0
- data/guides/output/contributing_to_ruby_on_rails.html +657 -0
- data/guides/output/credits.html +284 -0
- data/guides/output/debugging_rails_applications.html +1014 -0
- data/guides/output/development_dependencies_install.html +478 -0
- data/guides/output/engines.html +1438 -0
- data/guides/output/form_helpers.html +1074 -0
- data/guides/output/generators.html +838 -0
- data/guides/output/getting_started.html +2092 -0
- data/guides/output/i18n.html +1198 -0
- data/guides/output/images/akshaysurve.jpg +0 -0
- data/guides/output/images/belongs_to.png +0 -0
- data/guides/output/images/book_icon.gif +0 -0
- data/guides/output/images/bullet.gif +0 -0
- data/guides/output/images/chapters_icon.gif +0 -0
- data/guides/output/images/check_bullet.gif +0 -0
- data/guides/output/images/credits_pic_blank.gif +0 -0
- data/guides/output/images/csrf.png +0 -0
- data/guides/output/images/edge_badge.png +0 -0
- data/guides/output/images/favicon.ico +0 -0
- data/guides/output/images/feature_tile.gif +0 -0
- data/guides/output/images/footer_tile.gif +0 -0
- data/guides/output/images/fxn.png +0 -0
- data/guides/output/images/getting_started/article_with_comments.png +0 -0
- data/guides/output/images/getting_started/challenge.png +0 -0
- data/guides/output/images/getting_started/confirm_dialog.png +0 -0
- data/guides/output/images/getting_started/forbidden_attributes_for_new_article.png +0 -0
- data/guides/output/images/getting_started/forbidden_attributes_for_new_post.png +0 -0
- data/guides/output/images/getting_started/form_with_errors.png +0 -0
- data/guides/output/images/getting_started/index_action_with_edit_link.png +0 -0
- data/guides/output/images/getting_started/new_article.png +0 -0
- data/guides/output/images/getting_started/new_post.png +0 -0
- data/guides/output/images/getting_started/post_with_comments.png +0 -0
- data/guides/output/images/getting_started/rails_welcome.png +0 -0
- data/guides/output/images/getting_started/routing_error_no_controller.png +0 -0
- data/guides/output/images/getting_started/routing_error_no_route_matches.png +0 -0
- data/guides/output/images/getting_started/show_action_for_articles.png +0 -0
- data/guides/output/images/getting_started/show_action_for_posts.png +0 -0
- data/guides/output/images/getting_started/template_is_missing_articles_new.png +0 -0
- data/guides/output/images/getting_started/template_is_missing_posts_new.png +0 -0
- data/guides/output/images/getting_started/undefined_method_post_path.png +0 -0
- data/guides/output/images/getting_started/unknown_action_create_for_articles.png +0 -0
- data/guides/output/images/getting_started/unknown_action_create_for_posts.png +0 -0
- data/guides/output/images/getting_started/unknown_action_new_for_articles.png +0 -0
- data/guides/output/images/getting_started/unknown_action_new_for_posts.png +0 -0
- data/guides/output/images/grey_bullet.gif +0 -0
- data/guides/output/images/habtm.png +0 -0
- data/guides/output/images/has_many.png +0 -0
- data/guides/output/images/has_many_through.png +0 -0
- data/guides/output/images/has_one.png +0 -0
- data/guides/output/images/has_one_through.png +0 -0
- data/guides/output/images/header_backdrop.png +0 -0
- data/guides/output/images/header_tile.gif +0 -0
- data/guides/output/images/i18n/demo_html_safe.png +0 -0
- data/guides/output/images/i18n/demo_localized_pirate.png +0 -0
- data/guides/output/images/i18n/demo_translated_en.png +0 -0
- data/guides/output/images/i18n/demo_translated_pirate.png +0 -0
- data/guides/output/images/i18n/demo_translation_missing.png +0 -0
- data/guides/output/images/i18n/demo_untranslated.png +0 -0
- data/guides/output/images/icons/README +5 -0
- data/guides/output/images/icons/callouts/1.png +0 -0
- data/guides/output/images/icons/callouts/10.png +0 -0
- data/guides/output/images/icons/callouts/11.png +0 -0
- data/guides/output/images/icons/callouts/12.png +0 -0
- data/guides/output/images/icons/callouts/13.png +0 -0
- data/guides/output/images/icons/callouts/14.png +0 -0
- data/guides/output/images/icons/callouts/15.png +0 -0
- data/guides/output/images/icons/callouts/2.png +0 -0
- data/guides/output/images/icons/callouts/3.png +0 -0
- data/guides/output/images/icons/callouts/4.png +0 -0
- data/guides/output/images/icons/callouts/5.png +0 -0
- data/guides/output/images/icons/callouts/6.png +0 -0
- data/guides/output/images/icons/callouts/7.png +0 -0
- data/guides/output/images/icons/callouts/8.png +0 -0
- data/guides/output/images/icons/callouts/9.png +0 -0
- data/guides/output/images/icons/caution.png +0 -0
- data/guides/output/images/icons/example.png +0 -0
- data/guides/output/images/icons/home.png +0 -0
- data/guides/output/images/icons/important.png +0 -0
- data/guides/output/images/icons/next.png +0 -0
- data/guides/output/images/icons/note.png +0 -0
- data/guides/output/images/icons/prev.png +0 -0
- data/guides/output/images/icons/tip.png +0 -0
- data/guides/output/images/icons/up.png +0 -0
- data/guides/output/images/icons/warning.png +0 -0
- data/guides/output/images/nav_arrow.gif +0 -0
- data/guides/output/images/oscardelben.jpg +0 -0
- data/guides/output/images/polymorphic.png +0 -0
- data/guides/output/images/radar.png +0 -0
- data/guides/output/images/rails4_features.png +0 -0
- data/guides/output/images/rails_guides_kindle_cover.jpg +0 -0
- data/guides/output/images/rails_guides_logo.gif +0 -0
- data/guides/output/images/rails_logo_remix.gif +0 -0
- data/guides/output/images/session_fixation.png +0 -0
- data/guides/output/images/tab_grey.gif +0 -0
- data/guides/output/images/tab_info.gif +0 -0
- data/guides/output/images/tab_note.gif +0 -0
- data/guides/output/images/tab_red.gif +0 -0
- data/guides/output/images/tab_yellow.gif +0 -0
- data/guides/output/images/tab_yellow.png +0 -0
- data/guides/output/images/vijaydev.jpg +0 -0
- data/guides/output/index.html +354 -0
- data/guides/output/initialization.html +876 -0
- data/guides/output/javascripts/guides.js +59 -0
- data/guides/output/javascripts/jquery.min.js +4 -0
- data/guides/output/javascripts/responsive-tables.js +43 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushAS3.js +59 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushAppleScript.js +75 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushBash.js +59 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushCSharp.js +65 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushColdFusion.js +100 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushCpp.js +97 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushCss.js +91 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushDelphi.js +55 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushDiff.js +41 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushErlang.js +52 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushGroovy.js +67 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushJScript.js +52 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushJava.js +57 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushJavaFX.js +58 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushPerl.js +72 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushPhp.js +88 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushPlain.js +33 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushPowerShell.js +74 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushPython.js +64 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushRuby.js +55 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushSass.js +94 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushScala.js +51 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushSql.js +66 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushVb.js +56 -0
- data/guides/output/javascripts/syntaxhighlighter/shBrushXml.js +69 -0
- data/guides/output/javascripts/syntaxhighlighter/shCore.js +17 -0
- data/guides/output/layout.html +448 -0
- data/guides/output/layouts_and_rendering.html +1541 -0
- data/guides/output/maintenance_policy.html +257 -0
- data/guides/output/migrations.html +1360 -0
- data/guides/output/nested_model_forms.html +412 -0
- data/guides/output/plugins.html +644 -0
- data/guides/output/rails_application_templates.html +450 -0
- data/guides/output/rails_on_rack.html +547 -0
- data/guides/output/routing.html +1631 -0
- data/guides/output/ruby_on_rails_guides_guidelines.html +329 -0
- data/guides/output/security.html +935 -0
- data/guides/output/stylesheets/fixes.css +16 -0
- data/guides/output/stylesheets/kindle.css +11 -0
- data/guides/output/stylesheets/main.css +713 -0
- data/guides/output/stylesheets/print.css +52 -0
- data/guides/output/stylesheets/reset.css +43 -0
- data/guides/output/stylesheets/responsive-tables.css +50 -0
- data/guides/output/stylesheets/style.css +13 -0
- data/guides/output/stylesheets/syntaxhighlighter/shCore.css +226 -0
- data/guides/output/stylesheets/syntaxhighlighter/shCoreDefault.css +328 -0
- data/guides/output/stylesheets/syntaxhighlighter/shCoreDjango.css +331 -0
- data/guides/output/stylesheets/syntaxhighlighter/shCoreEclipse.css +339 -0
- data/guides/output/stylesheets/syntaxhighlighter/shCoreEmacs.css +324 -0
- data/guides/output/stylesheets/syntaxhighlighter/shCoreFadeToGrey.css +328 -0
- data/guides/output/stylesheets/syntaxhighlighter/shCoreMDUltra.css +324 -0
- data/guides/output/stylesheets/syntaxhighlighter/shCoreMidnight.css +324 -0
- data/guides/output/stylesheets/syntaxhighlighter/shCoreRDark.css +324 -0
- data/guides/output/stylesheets/syntaxhighlighter/shThemeDefault.css +117 -0
- data/guides/output/stylesheets/syntaxhighlighter/shThemeDjango.css +120 -0
- data/guides/output/stylesheets/syntaxhighlighter/shThemeEclipse.css +128 -0
- data/guides/output/stylesheets/syntaxhighlighter/shThemeEmacs.css +113 -0
- data/guides/output/stylesheets/syntaxhighlighter/shThemeFadeToGrey.css +117 -0
- data/guides/output/stylesheets/syntaxhighlighter/shThemeMDUltra.css +113 -0
- data/guides/output/stylesheets/syntaxhighlighter/shThemeMidnight.css +113 -0
- data/guides/output/stylesheets/syntaxhighlighter/shThemeRDark.css +113 -0
- data/guides/output/stylesheets/syntaxhighlighter/shThemeRailsGuides.css +116 -0
- data/guides/output/testing.html +1350 -0
- data/guides/output/upgrading_ruby_on_rails.html +1135 -0
- data/guides/output/working_with_javascript_in_rails.html +587 -0
- data/guides/source/4_0_release_notes.md +2 -2
- data/guides/source/4_2_release_notes.md +9 -2
- data/guides/source/action_controller_overview.md +3 -1
- data/guides/source/action_mailer_basics.md +1 -2
- data/guides/source/active_job_basics.md +25 -2
- data/guides/source/active_model_basics.md +350 -19
- data/guides/source/active_record_basics.md +2 -2
- data/guides/source/active_record_migrations.md +1 -1
- data/guides/source/active_record_validations.md +12 -4
- data/guides/source/active_support_core_extensions.md +7 -9
- data/guides/source/active_support_instrumentation.md +2 -0
- data/guides/source/association_basics.md +7 -7
- data/guides/source/configuring.md +24 -0
- data/guides/source/contributing_to_ruby_on_rails.md +1 -1
- data/guides/source/credits.html.erb +1 -1
- data/guides/source/documents.yaml +5 -0
- data/guides/source/engines.md +2 -2
- data/guides/source/form_helpers.md +6 -0
- data/guides/source/i18n.md +6 -9
- data/guides/source/layouts_and_rendering.md +1 -1
- data/guides/source/plugins.md +2 -2
- data/guides/source/rails_on_rack.md +4 -0
- data/guides/source/testing.md +1 -0
- data/guides/source/upgrading_ruby_on_rails.md +5 -5
- metadata +227 -27
@@ -0,0 +1,1135 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
7
|
+
|
8
|
+
<title>A Guide for Upgrading Ruby on Rails — Ruby on Rails Guides</title>
|
9
|
+
<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
|
10
|
+
<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
|
11
|
+
|
12
|
+
<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
|
13
|
+
<link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" type="text/css" href="stylesheets/fixes.css" />
|
16
|
+
|
17
|
+
<link href="images/favicon.ico" rel="shortcut icon" type="image/x-icon" />
|
18
|
+
</head>
|
19
|
+
<body class="guide">
|
20
|
+
<div id="topNav">
|
21
|
+
<div class="wrapper">
|
22
|
+
<strong class="more-info-label">More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
|
23
|
+
<span class="red-button more-info-button">
|
24
|
+
More Ruby on Rails
|
25
|
+
</span>
|
26
|
+
<ul class="more-info-links s-hidden">
|
27
|
+
<li class="more-info"><a href="http://rubyonrails.org/">Overview</a></li>
|
28
|
+
<li class="more-info"><a href="http://rubyonrails.org/download">Download</a></li>
|
29
|
+
<li class="more-info"><a href="http://rubyonrails.org/deploy">Deploy</a></li>
|
30
|
+
<li class="more-info"><a href="https://github.com/rails/rails">Code</a></li>
|
31
|
+
<li class="more-info"><a href="http://rubyonrails.org/screencasts">Screencasts</a></li>
|
32
|
+
<li class="more-info"><a href="http://rubyonrails.org/documentation">Documentation</a></li>
|
33
|
+
<li class="more-info"><a href="http://rubyonrails.org/community">Community</a></li>
|
34
|
+
<li class="more-info"><a href="http://weblog.rubyonrails.org/">Blog</a></li>
|
35
|
+
</ul>
|
36
|
+
</div>
|
37
|
+
</div>
|
38
|
+
<div id="header">
|
39
|
+
<div class="wrapper clearfix">
|
40
|
+
<h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
|
41
|
+
<ul class="nav">
|
42
|
+
<li><a class="nav-item" href="index.html">Home</a></li>
|
43
|
+
<li class="guides-index guides-index-large">
|
44
|
+
<a href="index.html" id="guidesMenu" class="guides-index-item nav-item">Guides Index</a>
|
45
|
+
<div id="guides" class="clearfix" style="display: none;">
|
46
|
+
<hr />
|
47
|
+
<dl class="L">
|
48
|
+
<dt>Start Here</dt>
|
49
|
+
<dd><a href="getting_started.html">Getting Started with Rails</a></dd>
|
50
|
+
<dt>Models</dt>
|
51
|
+
<dd><a href="active_record_basics.html">Active Record Basics</a></dd>
|
52
|
+
<dd><a href="active_record_migrations.html">Active Record Migrations</a></dd>
|
53
|
+
<dd><a href="active_record_validations.html">Active Record Validations</a></dd>
|
54
|
+
<dd><a href="active_record_callbacks.html">Active Record Callbacks</a></dd>
|
55
|
+
<dd><a href="association_basics.html">Active Record Associations</a></dd>
|
56
|
+
<dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
|
57
|
+
<dt>Views</dt>
|
58
|
+
<dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
|
59
|
+
<dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
|
60
|
+
<dt>Controllers</dt>
|
61
|
+
<dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
|
62
|
+
<dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
|
63
|
+
</dl>
|
64
|
+
<dl class="R">
|
65
|
+
<dt>Digging Deeper</dt>
|
66
|
+
<dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
|
67
|
+
<dd><a href="i18n.html">Rails Internationalization API</a></dd>
|
68
|
+
<dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
|
69
|
+
<dd><a href="active_job_basics.html">Active Job Basics</a></dd>
|
70
|
+
<dd><a href="security.html">Securing Rails Applications</a></dd>
|
71
|
+
<dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
|
72
|
+
<dd><a href="configuring.html">Configuring Rails Applications</a></dd>
|
73
|
+
<dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
|
74
|
+
<dd><a href="asset_pipeline.html">Asset Pipeline</a></dd>
|
75
|
+
<dd><a href="working_with_javascript_in_rails.html">Working with JavaScript in Rails</a></dd>
|
76
|
+
<dt>Extending Rails</dt>
|
77
|
+
<dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
|
78
|
+
<dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
|
79
|
+
<dt>Contributing to Ruby on Rails</dt>
|
80
|
+
<dd><a href="contributing_to_ruby_on_rails.html">Contributing to Ruby on Rails</a></dd>
|
81
|
+
<dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
|
82
|
+
<dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
|
83
|
+
<dt>Maintenance Policy</dt>
|
84
|
+
<dd><a href="maintenance_policy.html">Maintenance Policy</a></dd>
|
85
|
+
<dt>Release Notes</dt>
|
86
|
+
<dd><a href="upgrading_ruby_on_rails.html">Upgrading Ruby on Rails</a></dd>
|
87
|
+
<dd><a href="4_1_release_notes.html">Ruby on Rails 4.1 Release Notes</a></dd>
|
88
|
+
<dd><a href="4_0_release_notes.html">Ruby on Rails 4.0 Release Notes</a></dd>
|
89
|
+
<dd><a href="3_2_release_notes.html">Ruby on Rails 3.2 Release Notes</a></dd>
|
90
|
+
<dd><a href="3_1_release_notes.html">Ruby on Rails 3.1 Release Notes</a></dd>
|
91
|
+
<dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
|
92
|
+
<dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
|
93
|
+
<dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
|
94
|
+
</dl>
|
95
|
+
</div>
|
96
|
+
</li>
|
97
|
+
<li><a class="nav-item" href="contributing_to_ruby_on_rails.html">Contribute</a></li>
|
98
|
+
<li><a class="nav-item" href="credits.html">Credits</a></li>
|
99
|
+
<li class="guides-index guides-index-small">
|
100
|
+
<select class="guides-index-item nav-item">
|
101
|
+
<option value="index.html">Guides Index</option>
|
102
|
+
<optgroup label="Start Here">
|
103
|
+
<option value="getting_started.html">Getting Started with Rails</option>
|
104
|
+
</optgroup>
|
105
|
+
<optgroup label="Models">
|
106
|
+
<option value="active_record_basics.html">Active Record Basics</option>
|
107
|
+
<option value="active_record_migrations.html">Active Record Migrations</option>
|
108
|
+
<option value="active_record_validations.html">Active Record Validations</option>
|
109
|
+
<option value="active_record_callbacks.html">Active Record Callbacks</option>
|
110
|
+
<option value="association_basics.html">Active Record Associations</option>
|
111
|
+
<option value="active_record_querying.html">Active Record Query Interface</option>
|
112
|
+
</optgroup>
|
113
|
+
<optgroup label="Views">
|
114
|
+
<option value="layouts_and_rendering.html">Layouts and Rendering in Rails</option>
|
115
|
+
<option value="form_helpers.html">Action View Form Helpers</option>
|
116
|
+
</optgroup>
|
117
|
+
<optgroup label="Controllers">
|
118
|
+
<option value="action_controller_overview.html">Action Controller Overview</option>
|
119
|
+
<option value="routing.html">Rails Routing from the Outside In</option>
|
120
|
+
</optgroup>
|
121
|
+
<optgroup label="Digging Deeper">
|
122
|
+
<option value="active_support_core_extensions.html">Active Support Core Extensions</option>
|
123
|
+
<option value="i18n.html">Rails Internationalization API</option>
|
124
|
+
<option value="action_mailer_basics.html">Action Mailer Basics</option>
|
125
|
+
<option value="active_job_basics.html">Active Job Basics</option>
|
126
|
+
<option value="security.html">Securing Rails Applications</option>
|
127
|
+
<option value="debugging_rails_applications.html">Debugging Rails Applications</option>
|
128
|
+
<option value="configuring.html">Configuring Rails Applications</option>
|
129
|
+
<option value="command_line.html">Rails Command Line Tools and Rake Tasks</option>
|
130
|
+
<option value="asset_pipeline.html">Asset Pipeline</option>
|
131
|
+
<option value="working_with_javascript_in_rails.html">Working with JavaScript in Rails</option>
|
132
|
+
</optgroup>
|
133
|
+
<optgroup label="Extending Rails">
|
134
|
+
<option value="rails_on_rack.html">Rails on Rack</option>
|
135
|
+
<option value="generators.html">Creating and Customizing Rails Generators</option>
|
136
|
+
</optgroup>
|
137
|
+
<optgroup label="Contributing to Ruby on Rails">
|
138
|
+
<option value="contributing_to_ruby_on_rails.html">Contributing to Ruby on Rails</option>
|
139
|
+
<option value="api_documentation_guidelines.html">API Documentation Guidelines</option>
|
140
|
+
<option value="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</option>
|
141
|
+
</optgroup>
|
142
|
+
<optgroup label="Maintenance Policy">
|
143
|
+
<option value="maintenance_policy.html">Maintenance Policy</option>
|
144
|
+
</optgroup>
|
145
|
+
<optgroup label="Release Notes">
|
146
|
+
<option value="upgrading_ruby_on_rails.html">Upgrading Ruby on Rails</option>
|
147
|
+
<option value="4_1_release_notes.html">Ruby on Rails 4.1 Release Notes</option>
|
148
|
+
<option value="4_0_release_notes.html">Ruby on Rails 4.0 Release Notes</option>
|
149
|
+
<option value="3_2_release_notes.html">Ruby on Rails 3.2 Release Notes</option>
|
150
|
+
<option value="3_1_release_notes.html">Ruby on Rails 3.1 Release Notes</option>
|
151
|
+
<option value="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</option>
|
152
|
+
<option value="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</option>
|
153
|
+
<option value="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</option>
|
154
|
+
</optgroup>
|
155
|
+
</select>
|
156
|
+
</li>
|
157
|
+
</ul>
|
158
|
+
</div>
|
159
|
+
</div>
|
160
|
+
<hr class="hide" />
|
161
|
+
|
162
|
+
<div id="feature">
|
163
|
+
<div class="wrapper">
|
164
|
+
<h2>A Guide for 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>
|
165
|
+
|
166
|
+
<div id="subCol">
|
167
|
+
<h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
|
168
|
+
<ol class="chapters">
|
169
|
+
<li>
|
170
|
+
<a href="#general-advice">General Advice</a>
|
171
|
+
|
172
|
+
<ul>
|
173
|
+
<li><a href="#test-coverage">Test Coverage</a></li>
|
174
|
+
<li><a href="#ruby-versions">Ruby Versions</a></li>
|
175
|
+
<li><a href="#the-rake-task">The Rake Task</a></li>
|
176
|
+
</ul>
|
177
|
+
</li>
|
178
|
+
<li>
|
179
|
+
<a href="#upgrading-from-rails-4.1-to-rails-4.2">Upgrading from Rails 4.1 to Rails 4.2</a>
|
180
|
+
|
181
|
+
<ul>
|
182
|
+
<li><a href="#web-console">Web Console</a></li>
|
183
|
+
<li><a href="#responders">Responders</a></li>
|
184
|
+
<li><a href="#error-handling-in-transaction-callbacks">Error handling in transaction callbacks</a></li>
|
185
|
+
<li><a href="#serialized-attributes">Serialized attributes</a></li>
|
186
|
+
<li><a href="#after_bundle-in-rails-templates"><code>after_bundle</code> in Rails templates</a></li>
|
187
|
+
<li><a href="#rails-html-sanitizer">Rails Html Sanitizer</a></li>
|
188
|
+
<li><a href="#rails-dom-testing">Rails DOM Testing</a></li>
|
189
|
+
</ul>
|
190
|
+
</li>
|
191
|
+
<li>
|
192
|
+
<a href="#upgrading-from-rails-4.0-to-rails-4.1">Upgrading from Rails 4.0 to Rails 4.1</a>
|
193
|
+
|
194
|
+
<ul>
|
195
|
+
<li><a href="#csrf-protection-from-remote-%3Cscript%3E-tags">CSRF protection from remote <code><script></code> tags</a></li>
|
196
|
+
<li><a href="#spring">Spring</a></li>
|
197
|
+
<li><a href="#config/secrets.yml"><code>config/secrets.yml</code></a></li>
|
198
|
+
<li><a href="#changes-to-test-helper">Changes to test helper</a></li>
|
199
|
+
<li><a href="#cookies-serializer">Cookies serializer</a></li>
|
200
|
+
<li><a href="#flash-structure-changes">Flash structure changes</a></li>
|
201
|
+
<li><a href="#changes-in-json-handling">Changes in JSON handling</a></li>
|
202
|
+
<li><a href="#usage-of-return-within-inline-callback-blocks">Usage of <code>return</code> within inline callback blocks</a></li>
|
203
|
+
<li><a href="#methods-defined-in-active-record-fixtures">Methods defined in Active Record fixtures</a></li>
|
204
|
+
<li><a href="#i18n-enforcing-available-locales">I18n enforcing available locales</a></li>
|
205
|
+
<li><a href="#mutator-methods-called-on-relation">Mutator methods called on Relation</a></li>
|
206
|
+
<li><a href="#changes-on-default-scopes">Changes on Default Scopes</a></li>
|
207
|
+
<li><a href="#rendering-content-from-string">Rendering content from string</a></li>
|
208
|
+
<li><a href="#postgresql-json-and-hstore-datatypes">PostgreSQL json and hstore datatypes</a></li>
|
209
|
+
<li><a href="#explicit-block-use-for-activesupport::callbacks">Explicit block use for <code>ActiveSupport::Callbacks</code></a></li>
|
210
|
+
</ul>
|
211
|
+
</li>
|
212
|
+
<li>
|
213
|
+
<a href="#upgrading-from-rails-3.2-to-rails-4.0">Upgrading from Rails 3.2 to Rails 4.0</a>
|
214
|
+
|
215
|
+
<ul>
|
216
|
+
<li><a href="#http-patch">HTTP PATCH</a></li>
|
217
|
+
<li><a href="#upgrading-from-rails-3.2-to-rails-4.0-gemfile">Gemfile</a></li>
|
218
|
+
<li><a href="#upgrading-from-rails-3.2-to-rails-4.0-vendor/plugins">vendor/plugins</a></li>
|
219
|
+
<li><a href="#upgrading-from-rails-3.2-to-rails-4.0-active-record">Active Record</a></li>
|
220
|
+
<li><a href="#active-resource">Active Resource</a></li>
|
221
|
+
<li><a href="#active-model">Active Model</a></li>
|
222
|
+
<li><a href="#action-pack">Action Pack</a></li>
|
223
|
+
<li><a href="#active-support">Active Support</a></li>
|
224
|
+
<li><a href="#helpers-loading-order">Helpers Loading Order</a></li>
|
225
|
+
<li><a href="#active-record-observer-and-action-controller-sweeper">Active Record Observer and Action Controller Sweeper</a></li>
|
226
|
+
<li><a href="#sprockets-rails">sprockets-rails</a></li>
|
227
|
+
<li><a href="#sass-rails">sass-rails</a></li>
|
228
|
+
</ul>
|
229
|
+
</li>
|
230
|
+
<li>
|
231
|
+
<a href="#upgrading-from-rails-3.1-to-rails-3.2">Upgrading from Rails 3.1 to Rails 3.2</a>
|
232
|
+
|
233
|
+
<ul>
|
234
|
+
<li><a href="#upgrading-from-rails-3.1-to-rails-3.2-gemfile">Gemfile</a></li>
|
235
|
+
<li><a href="#upgrading-from-rails-3.1-to-rails-3.2-config/environments/development.rb">config/environments/development.rb</a></li>
|
236
|
+
<li><a href="#upgrading-from-rails-3.1-to-rails-3.2-config/environments/test.rb">config/environments/test.rb</a></li>
|
237
|
+
<li><a href="#upgrading-from-rails-3.1-to-rails-3.2-vendor/plugins">vendor/plugins</a></li>
|
238
|
+
<li><a href="#upgrading-from-rails-3.1-to-rails-3.2-active-record">Active Record</a></li>
|
239
|
+
</ul>
|
240
|
+
</li>
|
241
|
+
<li>
|
242
|
+
<a href="#upgrading-from-rails-3.0-to-rails-3.1">Upgrading from Rails 3.0 to Rails 3.1</a>
|
243
|
+
|
244
|
+
<ul>
|
245
|
+
<li><a href="#gemfile">Gemfile</a></li>
|
246
|
+
<li><a href="#config/application.rb">config/application.rb</a></li>
|
247
|
+
<li><a href="#upgrading-from-rails-3.0-to-rails-3.1-config/environments/development.rb">config/environments/development.rb</a></li>
|
248
|
+
<li><a href="#config/environments/production.rb">config/environments/production.rb</a></li>
|
249
|
+
<li><a href="#upgrading-from-rails-3.0-to-rails-3.1-config/environments/test.rb">config/environments/test.rb</a></li>
|
250
|
+
<li><a href="#config/initializers/wrap_parameters.rb">config/initializers/wrap_parameters.rb</a></li>
|
251
|
+
<li><a href="#config/initializers/session_store.rb">config/initializers/session_store.rb</a></li>
|
252
|
+
<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>
|
253
|
+
</ul>
|
254
|
+
</li>
|
255
|
+
</ol>
|
256
|
+
|
257
|
+
</div>
|
258
|
+
|
259
|
+
</div>
|
260
|
+
</div>
|
261
|
+
|
262
|
+
<div id="container">
|
263
|
+
<div class="wrapper">
|
264
|
+
<div id="mainCol">
|
265
|
+
<h3 id="general-advice">1 General Advice</h3><p>Before attempting to upgrade an existing application, you should be sure you have a good reason to upgrade. You need to balance out 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">1.1 Test Coverage</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="ruby-versions">1.2 Ruby Versions</h4><p>Rails generally stays close to the latest released Ruby version when it's released:</p>
|
266
|
+
<ul>
|
267
|
+
<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>
|
268
|
+
<li>Rails 3.2.x is the last branch to support Ruby 1.8.7.</li>
|
269
|
+
<li>Rails 4 prefers Ruby 2.0 and requires 1.9.3 or newer.</li>
|
270
|
+
</ul>
|
271
|
+
<div class="info"><p>Ruby 1.8.7 p248 and p249 have marshaling 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-rake-task">1.3 The Rake Task</h4><p>Rails provides the <code>rails:update</code> rake task. After updating the Rails version
|
272
|
+
in the Gemfile, run this rake task.
|
273
|
+
This will help you with the creation of new files and changes of old files in a
|
274
|
+
interactive session.</p><div class="code_container">
|
275
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
276
|
+
$ rake rails:update
|
277
|
+
identical config/boot.rb
|
278
|
+
exist config
|
279
|
+
conflict config/routes.rb
|
280
|
+
Overwrite /myapp/config/routes.rb? (enter "h" for help) [Ynaqdh]
|
281
|
+
force config/routes.rb
|
282
|
+
conflict config/application.rb
|
283
|
+
Overwrite /myapp/config/application.rb? (enter "h" for help) [Ynaqdh]
|
284
|
+
force config/application.rb
|
285
|
+
conflict config/environment.rb
|
286
|
+
...
|
287
|
+
|
288
|
+
</pre>
|
289
|
+
</div>
|
290
|
+
<p>Don't forget to review the difference, to see if there were any unexpected changes.</p><h3 id="upgrading-from-rails-4.1-to-rails-4.2">2 Upgrading from Rails 4.1 to Rails 4.2</h3><div class="note"><p>This section is a work in progress, please help to improve this by sending
|
291
|
+
a <a href="https://github.com/rails/rails/edit/master/guides/source/upgrading_ruby_on_rails.md">pull request</a>.</p></div><h4 id="web-console">2.1 Web Console</h4><div class="todo"><p>setup instructions for web console on existing apps.</p></div><h4 id="responders">2.2 Responders</h4><div class="todo"><p>mention <a href="https://github.com/rails/rails/pull/16526">https://github.com/rails/rails/pull/16526</a></p></div><h4 id="error-handling-in-transaction-callbacks">2.3 Error handling in transaction callbacks</h4><div class="todo"><p>mention <a href="https://github.com/rails/rails/pull/16537">https://github.com/rails/rails/pull/16537</a></p></div><h4 id="serialized-attributes">2.4 Serialized attributes</h4><p>When using a custom coder (e.g. <code>serialize :metadata, JSON</code>),
|
292
|
+
assigning <code>nil</code> to a serialized attribute will save it to the database
|
293
|
+
as <code>NULL</code> instead of passing the <code>nil</code> value through the coder (e.g. <code>"null"</code>
|
294
|
+
when using the <code>JSON</code> coder).</p><h4 id="after_bundle-in-rails-templates">2.5 <code>after_bundle</code> in Rails templates</h4><p>If you have a Rails template that adds all the files in version control, it
|
295
|
+
fails to add the generated binstubs because it gets executed before Bundler:</p><div class="code_container">
|
296
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
297
|
+
# template.rb
|
298
|
+
generate(:scaffold, "person name:string")
|
299
|
+
route "root to: 'people#index'"
|
300
|
+
rake("db:migrate")
|
301
|
+
|
302
|
+
git :init
|
303
|
+
git add: "."
|
304
|
+
git commit: %Q{ -m 'Initial commit' }
|
305
|
+
|
306
|
+
</pre>
|
307
|
+
</div>
|
308
|
+
<p>You can now wrap the <code>git</code> calls in an <code>after_bundle</code> block. It will be run
|
309
|
+
after the binstubs have been generated.</p><div class="code_container">
|
310
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
311
|
+
# template.rb
|
312
|
+
generate(:scaffold, "person name:string")
|
313
|
+
route "root to: 'people#index'"
|
314
|
+
rake("db:migrate")
|
315
|
+
|
316
|
+
after_bundle do
|
317
|
+
git :init
|
318
|
+
git add: "."
|
319
|
+
git commit: %Q{ -m 'Initial commit' }
|
320
|
+
end
|
321
|
+
|
322
|
+
</pre>
|
323
|
+
</div>
|
324
|
+
<h4 id="rails-html-sanitizer">2.6 Rails Html Sanitizer</h4><p>There's a new choice for sanitizing HTML fragments in your applications. The
|
325
|
+
venerable html-scanner approach is now officially being deprecated in favor of
|
326
|
+
<a href="https://github.com/rails/rails-html-sanitizer"><code>Rails Html Sanitizer</code></a>.</p><p>This means the methods <code>sanitize</code>, <code>sanitize_css</code>, <code>strip_tags</code> and
|
327
|
+
<code>strip_links</code> are backed by a new implementation.</p><p>In the next major Rails version <code>Rails Html Sanitizer</code> will be the default
|
328
|
+
sanitizer. It already is for new applications.</p><p>Include this in your Gemfile to try it out today:</p><div class="code_container">
|
329
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
330
|
+
gem 'rails-html-sanitizer'
|
331
|
+
|
332
|
+
</pre>
|
333
|
+
</div>
|
334
|
+
<p>This new sanitizer uses <a href="https://github.com/flavorjones/loofah">Loofah</a> internally. Loofah in turn uses Nokogiri, which
|
335
|
+
wraps XML parsers written in both C and Java, so sanitization should be faster
|
336
|
+
no matter which Ruby version you run.</p><p>The new version updates <code>sanitize</code>, so it can take a <code>Loofah::Scrubber</code> for
|
337
|
+
powerful scrubbing.
|
338
|
+
<a href="https://github.com/flavorjones/loofah#loofahscrubber">See some examples of scrubbers here</a>.</p><p>Two new scrubbers have also been added: <code>PermitScrubber</code> and <code>TargetScrubber</code>.
|
339
|
+
Read the <a href="https://github.com/rails/rails-html-sanitizer">gem's readme</a> for more information.</p><p>The documentation for <code>PermitScrubber</code> and <code>TargetScrubber</code> explains how you
|
340
|
+
can gain complete control over when and how elements should be stripped.</p><h4 id="rails-dom-testing">2.7 Rails DOM Testing</h4><div class="todo"><p>Mention <a href="https://github.com/rails/rails/commit/4e97d7585a2f4788b9eed98c6cdaf4bb6f2cf5ce">https://github.com/rails/rails/commit/4e97d7585a2f4788b9eed98c6cdaf4bb6f2cf5ce</a></p></div><h3 id="upgrading-from-rails-4.0-to-rails-4.1">3 Upgrading from Rails 4.0 to Rails 4.1</h3><h4 id="csrf-protection-from-remote-<script>-tags">3.1 CSRF protection from remote <code><script></code> tags</h4><p>Or, "whaaat my tests are failing!!!?"</p><p>Cross-site request forgery (CSRF) protection now covers GET requests with
|
341
|
+
JavaScript responses, too. That prevents a third-party site from referencing
|
342
|
+
your JavaScript URL and attempting to run it to extract sensitive data.</p><p>This means that your functional and integration tests that use</p><div class="code_container">
|
343
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
344
|
+
get :index, format: :js
|
345
|
+
|
346
|
+
</pre>
|
347
|
+
</div>
|
348
|
+
<p>will now trigger CSRF protection. Switch to</p><div class="code_container">
|
349
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
350
|
+
xhr :get, :index, format: :js
|
351
|
+
|
352
|
+
</pre>
|
353
|
+
</div>
|
354
|
+
<p>to explicitly test an XmlHttpRequest.</p><p>If you really mean to load JavaScript from remote <code><script></code> tags, skip CSRF
|
355
|
+
protection on that action.</p><h4 id="spring">3.2 Spring</h4><p>If you want to use Spring as your application preloader you need to:</p>
|
356
|
+
<ol>
|
357
|
+
<li>Add <code>gem 'spring', group: :development</code> to your <code>Gemfile</code>.</li>
|
358
|
+
<li>Install spring using <code>bundle install</code>.</li>
|
359
|
+
<li>Springify your binstubs with <code>bundle exec spring binstub --all</code>.</li>
|
360
|
+
</ol>
|
361
|
+
<div class="note"><p>User defined rake tasks will run in the <code>development</code> environment by
|
362
|
+
default. If you want them to run in other environments consult the
|
363
|
+
<a href="https://github.com/rails/spring#rake">Spring README</a>.</p></div><h4 id="config/secrets.yml">3.3 <code>config/secrets.yml</code>
|
364
|
+
</h4><p>If you want to use the new <code>secrets.yml</code> convention to store your application's
|
365
|
+
secrets, you need to:</p>
|
366
|
+
<ol>
|
367
|
+
<li>
|
368
|
+
<p>Create a <code>secrets.yml</code> file in your <code>config</code> folder with the following content:</p>
|
369
|
+
<div class="code_container">
|
370
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
371
|
+
development:
|
372
|
+
secret_key_base:
|
373
|
+
|
374
|
+
test:
|
375
|
+
secret_key_base:
|
376
|
+
|
377
|
+
production:
|
378
|
+
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
|
379
|
+
|
380
|
+
</pre>
|
381
|
+
</div>
|
382
|
+
</li>
|
383
|
+
<li><p>Use your existing <code>secret_key_base</code> from the <code>secret_token.rb</code> initializer to
|
384
|
+
set the SECRET_KEY_BASE environment variable for whichever users run the Rails
|
385
|
+
app in production mode. Alternately, you can simply copy the existing
|
386
|
+
<code>secret_key_base</code> from the <code>secret_token.rb</code> initializer to <code>secrets.yml</code>
|
387
|
+
under the <code>production</code> section, replacing '<%= ENV["SECRET_KEY_BASE"] %>'.</p></li>
|
388
|
+
<li><p>Remove the <code>secret_token.rb</code> initializer.</p></li>
|
389
|
+
<li><p>Use <code>rake secret</code> to generate new keys for the <code>development</code> and <code>test</code> sections.</p></li>
|
390
|
+
<li><p>Restart your server.</p></li>
|
391
|
+
</ol>
|
392
|
+
<h4 id="changes-to-test-helper">3.4 Changes to test helper</h4><p>If your test helper contains a call to
|
393
|
+
<code>ActiveRecord::Migration.check_pending!</code> this can be removed. The check
|
394
|
+
is now done automatically when you <code>require 'rails/test_help'</code>, although
|
395
|
+
leaving this line in your helper is not harmful in any way.</p><h4 id="cookies-serializer">3.5 Cookies serializer</h4><p>Applications created before Rails 4.1 uses <code>Marshal</code> to serialize cookie values into
|
396
|
+
the signed and encrypted cookie jars. If you want to use the new <code>JSON</code>-based format
|
397
|
+
in your application, you can add an initializer file with the following content:</p><div class="code_container">
|
398
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
399
|
+
Rails.application.config.action_dispatch.cookies_serializer = :hybrid
|
400
|
+
|
401
|
+
</pre>
|
402
|
+
</div>
|
403
|
+
<p>This would transparently migrate your existing <code>Marshal</code>-serialized cookies into the
|
404
|
+
new <code>JSON</code>-based format.</p><p>When using the <code>:json</code> or <code>:hybrid</code> serializer, you should beware that not all
|
405
|
+
Ruby objects can be serialized as JSON. For example, <code>Date</code> and <code>Time</code> objects
|
406
|
+
will be serialized as strings, and <code>Hash</code>es will have their keys stringified.</p><div class="code_container">
|
407
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
408
|
+
class CookiesController < ApplicationController
|
409
|
+
def set_cookie
|
410
|
+
cookies.encrypted[:expiration_date] = Date.tomorrow # => Thu, 20 Mar 2014
|
411
|
+
redirect_to action: 'read_cookie'
|
412
|
+
end
|
413
|
+
|
414
|
+
def read_cookie
|
415
|
+
cookies.encrypted[:expiration_date] # => "2014-03-20"
|
416
|
+
end
|
417
|
+
end
|
418
|
+
|
419
|
+
</pre>
|
420
|
+
</div>
|
421
|
+
<p>It's advisable that you only store simple data (strings and numbers) in cookies.
|
422
|
+
If you have to store complex objects, you would need to handle the conversion
|
423
|
+
manually when reading the values on subsequent requests.</p><p>If you use the cookie session store, this would apply to the <code>session</code> and
|
424
|
+
<code>flash</code> hash as well.</p><h4 id="flash-structure-changes">3.6 Flash structure changes</h4><p>Flash message keys are
|
425
|
+
<a href="https://github.com/rails/rails/commit/a668beffd64106a1e1fedb71cc25eaaa11baf0c1">normalized to strings</a>. They
|
426
|
+
can still be accessed using either symbols or strings. Looping through the flash
|
427
|
+
will always yield string keys:</p><div class="code_container">
|
428
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
429
|
+
flash["string"] = "a string"
|
430
|
+
flash[:symbol] = "a symbol"
|
431
|
+
|
432
|
+
# Rails < 4.1
|
433
|
+
flash.keys # => ["string", :symbol]
|
434
|
+
|
435
|
+
# Rails >= 4.1
|
436
|
+
flash.keys # => ["string", "symbol"]
|
437
|
+
|
438
|
+
</pre>
|
439
|
+
</div>
|
440
|
+
<p>Make sure you are comparing Flash message keys against strings.</p><h4 id="changes-in-json-handling">3.7 Changes in JSON handling</h4><p>There are a few major changes related to JSON handling in Rails 4.1.</p><h5 id="multijson-removal">3.7.1 MultiJSON removal</h5><p>MultiJSON has reached its <a href="https://github.com/rails/rails/pull/10576">end-of-life</a>
|
441
|
+
and has been removed from Rails.</p><p>If your application currently depend on MultiJSON directly, you have a few options:</p>
|
442
|
+
<ol>
|
443
|
+
<li><p>Add 'multi_json' to your Gemfile. Note that this might cease to work in the future</p></li>
|
444
|
+
<li><p>Migrate away from MultiJSON by using <code>obj.to_json</code>, and <code>JSON.parse(str)</code> instead.</p></li>
|
445
|
+
</ol>
|
446
|
+
<div class="warning"><p>Do not simply replace <code>MultiJson.dump</code> and <code>MultiJson.load</code> with
|
447
|
+
<code>JSON.dump</code> and <code>JSON.load</code>. These JSON gem APIs are meant for serializing and
|
448
|
+
deserializing arbitrary Ruby objects and are generally <a href="http://www.ruby-doc.org/stdlib-2.0.0/libdoc/json/rdoc/JSON.html#method-i-load">unsafe</a>.</p></div><h5 id="json-gem-compatibility">3.7.2 JSON gem compatibility</h5><p>Historically, Rails had some compatibility issues with the JSON gem. Using
|
449
|
+
<code>JSON.generate</code> and <code>JSON.dump</code> inside a Rails application could produce
|
450
|
+
unexpected errors.</p><p>Rails 4.1 fixed these issues by isolating its own encoder from the JSON gem. The
|
451
|
+
JSON gem APIs will function as normal, but they will not have access to any
|
452
|
+
Rails-specific features. For example:</p><div class="code_container">
|
453
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
454
|
+
class FooBar
|
455
|
+
def as_json(options = nil)
|
456
|
+
{ foo: 'bar' }
|
457
|
+
end
|
458
|
+
end
|
459
|
+
|
460
|
+
>> FooBar.new.to_json # => "{\"foo\":\"bar\"}"
|
461
|
+
>> JSON.generate(FooBar.new, quirks_mode: true) # => "\"#<FooBar:0x007fa80a481610>\""
|
462
|
+
|
463
|
+
</pre>
|
464
|
+
</div>
|
465
|
+
<h5 id="new-json-encoder">3.7.3 New JSON encoder</h5><p>The JSON encoder in Rails 4.1 has been rewritten to take advantage of the JSON
|
466
|
+
gem. For most applications, this should be a transparent change. However, as
|
467
|
+
part of the rewrite, the following features have been removed from the encoder:</p>
|
468
|
+
<ol>
|
469
|
+
<li>Circular data structure detection</li>
|
470
|
+
<li>Support for the <code>encode_json</code> hook</li>
|
471
|
+
<li>Option to encode <code>BigDecimal</code> objects as numbers instead of strings</li>
|
472
|
+
</ol>
|
473
|
+
<p>If your application depends on one of these features, you can get them back by
|
474
|
+
adding the <a href="https://github.com/rails/activesupport-json_encoder"><code>activesupport-json_encoder</code></a>
|
475
|
+
gem to your Gemfile.</p><h5 id="json-representation-of-time-objects">3.7.4 JSON representation of Time objects</h5><p><code>#as_json</code> for objects with time component (<code>Time</code>, <code>DateTime</code>, <code>ActiveSupport::TimeWithZone</code>)
|
476
|
+
now returns millisecond precision by default. If you need to keep old behavior with no millisecond
|
477
|
+
precision, set the following in an initializer:</p><div class="code_container">
|
478
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
479
|
+
ActiveSupport::JSON::Encoding.time_precision = 0
|
480
|
+
|
481
|
+
</pre>
|
482
|
+
</div>
|
483
|
+
<h4 id="usage-of-return-within-inline-callback-blocks">3.8 Usage of <code>return</code> within inline callback blocks</h4><p>Previously, Rails allowed inline callback blocks to use <code>return</code> this way:</p><div class="code_container">
|
484
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
485
|
+
class ReadOnlyModel < ActiveRecord::Base
|
486
|
+
before_save { return false } # BAD
|
487
|
+
end
|
488
|
+
|
489
|
+
</pre>
|
490
|
+
</div>
|
491
|
+
<p>This behaviour was never intentionally supported. Due to a change in the internals
|
492
|
+
of <code>ActiveSupport::Callbacks</code>, this is no longer allowed in Rails 4.1. Using a
|
493
|
+
<code>return</code> statement in an inline callback block causes a <code>LocalJumpError</code> to
|
494
|
+
be raised when the callback is executed.</p><p>Inline callback blocks using <code>return</code> can be refactored to evaluate to the
|
495
|
+
returned value:</p><div class="code_container">
|
496
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
497
|
+
class ReadOnlyModel < ActiveRecord::Base
|
498
|
+
before_save { false } # GOOD
|
499
|
+
end
|
500
|
+
|
501
|
+
</pre>
|
502
|
+
</div>
|
503
|
+
<p>Alternatively, if <code>return</code> is preferred it is recommended to explicitly define
|
504
|
+
a method:</p><div class="code_container">
|
505
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
506
|
+
class ReadOnlyModel < ActiveRecord::Base
|
507
|
+
before_save :before_save_callback # GOOD
|
508
|
+
|
509
|
+
private
|
510
|
+
def before_save_callback
|
511
|
+
return false
|
512
|
+
end
|
513
|
+
end
|
514
|
+
|
515
|
+
</pre>
|
516
|
+
</div>
|
517
|
+
<p>This change applies to most places in Rails where callbacks are used, including
|
518
|
+
Active Record and Active Model callbacks, as well as filters in Action
|
519
|
+
Controller (e.g. <code>before_action</code>).</p><p>See <a href="https://github.com/rails/rails/pull/13271">this pull request</a> for more
|
520
|
+
details.</p><h4 id="methods-defined-in-active-record-fixtures">3.9 Methods defined in Active Record fixtures</h4><p>Rails 4.1 evaluates each fixture's ERB in a separate context, so helper methods
|
521
|
+
defined in a fixture will not be available in other fixtures.</p><p>Helper methods that are used in multiple fixtures should be defined on modules
|
522
|
+
included in the newly introduced <code>ActiveRecord::FixtureSet.context_class</code>, in
|
523
|
+
<code>test_helper.rb</code>.</p><div class="code_container">
|
524
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
525
|
+
class FixtureFileHelpers
|
526
|
+
def file_sha(path)
|
527
|
+
Digest::SHA2.hexdigest(File.read(Rails.root.join('test/fixtures', path)))
|
528
|
+
end
|
529
|
+
end
|
530
|
+
ActiveRecord::FixtureSet.context_class.send :include, FixtureFileHelpers
|
531
|
+
|
532
|
+
</pre>
|
533
|
+
</div>
|
534
|
+
<h4 id="i18n-enforcing-available-locales">3.10 I18n enforcing available locales</h4><p>Rails 4.1 now defaults the I18n option <code>enforce_available_locales</code> to <code>true</code>,
|
535
|
+
meaning that it will make sure that all locales passed to it must be declared in
|
536
|
+
the <code>available_locales</code> list.</p><p>To disable it (and allow I18n to accept <em>any</em> locale option) add the following
|
537
|
+
configuration to your application:</p><div class="code_container">
|
538
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
539
|
+
config.i18n.enforce_available_locales = false
|
540
|
+
|
541
|
+
</pre>
|
542
|
+
</div>
|
543
|
+
<p>Note that this option was added as a security measure, to ensure user input could
|
544
|
+
not be used as locale information unless previously known, so it's recommended not
|
545
|
+
to disable this option unless you have a strong reason for doing so.</p><h4 id="mutator-methods-called-on-relation">3.11 Mutator methods called on Relation</h4><p><code>Relation</code> no longer has mutator methods like <code>#map!</code> and <code>#delete_if</code>. Convert
|
546
|
+
to an <code>Array</code> by calling <code>#to_a</code> before using these methods.</p><p>It intends to prevent odd bugs and confusion in code that call mutator
|
547
|
+
methods directly on the <code>Relation</code>.</p><div class="code_container">
|
548
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
549
|
+
# Instead of this
|
550
|
+
Author.where(name: 'Hank Moody').compact!
|
551
|
+
|
552
|
+
# Now you have to do this
|
553
|
+
authors = Author.where(name: 'Hank Moody').to_a
|
554
|
+
authors.compact!
|
555
|
+
|
556
|
+
</pre>
|
557
|
+
</div>
|
558
|
+
<h4 id="changes-on-default-scopes">3.12 Changes on Default Scopes</h4><p>Default scopes are no longer overridden by chained conditions.</p><p>In previous versions when you defined a <code>default_scope</code> in a model
|
559
|
+
it was overridden by chained conditions in the same field. Now it
|
560
|
+
is merged like any other scope.</p><p>Before:</p><div class="code_container">
|
561
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
562
|
+
class User < ActiveRecord::Base
|
563
|
+
default_scope { where state: 'pending' }
|
564
|
+
scope :active, -> { where state: 'active' }
|
565
|
+
scope :inactive, -> { where state: 'inactive' }
|
566
|
+
end
|
567
|
+
|
568
|
+
User.all
|
569
|
+
# SELECT "users".* FROM "users" WHERE "users"."state" = 'pending'
|
570
|
+
|
571
|
+
User.active
|
572
|
+
# SELECT "users".* FROM "users" WHERE "users"."state" = 'active'
|
573
|
+
|
574
|
+
User.where(state: 'inactive')
|
575
|
+
# SELECT "users".* FROM "users" WHERE "users"."state" = 'inactive'
|
576
|
+
|
577
|
+
</pre>
|
578
|
+
</div>
|
579
|
+
<p>After:</p><div class="code_container">
|
580
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
581
|
+
class User < ActiveRecord::Base
|
582
|
+
default_scope { where state: 'pending' }
|
583
|
+
scope :active, -> { where state: 'active' }
|
584
|
+
scope :inactive, -> { where state: 'inactive' }
|
585
|
+
end
|
586
|
+
|
587
|
+
User.all
|
588
|
+
# SELECT "users".* FROM "users" WHERE "users"."state" = 'pending'
|
589
|
+
|
590
|
+
User.active
|
591
|
+
# SELECT "users".* FROM "users" WHERE "users"."state" = 'pending' AND "users"."state" = 'active'
|
592
|
+
|
593
|
+
User.where(state: 'inactive')
|
594
|
+
# SELECT "users".* FROM "users" WHERE "users"."state" = 'pending' AND "users"."state" = 'inactive'
|
595
|
+
|
596
|
+
</pre>
|
597
|
+
</div>
|
598
|
+
<p>To get the previous behavior it is needed to explicitly remove the
|
599
|
+
<code>default_scope</code> condition using <code>unscoped</code>, <code>unscope</code>, <code>rewhere</code> or
|
600
|
+
<code>except</code>.</p><div class="code_container">
|
601
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
602
|
+
class User < ActiveRecord::Base
|
603
|
+
default_scope { where state: 'pending' }
|
604
|
+
scope :active, -> { unscope(where: :state).where(state: 'active') }
|
605
|
+
scope :inactive, -> { rewhere state: 'inactive' }
|
606
|
+
end
|
607
|
+
|
608
|
+
User.all
|
609
|
+
# SELECT "users".* FROM "users" WHERE "users"."state" = 'pending'
|
610
|
+
|
611
|
+
User.active
|
612
|
+
# SELECT "users".* FROM "users" WHERE "users"."state" = 'active'
|
613
|
+
|
614
|
+
User.inactive
|
615
|
+
# SELECT "users".* FROM "users" WHERE "users"."state" = 'inactive'
|
616
|
+
|
617
|
+
</pre>
|
618
|
+
</div>
|
619
|
+
<h4 id="rendering-content-from-string">3.13 Rendering content from string</h4><p>Rails 4.1 introduces <code>:plain</code>, <code>:html</code>, and <code>:body</code> options to <code>render</code>. Those
|
620
|
+
options are now the preferred way to render string-based content, as it allows
|
621
|
+
you to specify which content type you want the response sent as.</p>
|
622
|
+
<ul>
|
623
|
+
<li>
|
624
|
+
<code>render :plain</code> will set the content type to <code>text/plain</code>
|
625
|
+
</li>
|
626
|
+
<li>
|
627
|
+
<code>render :html</code> will set the content type to <code>text/html</code>
|
628
|
+
</li>
|
629
|
+
<li>
|
630
|
+
<code>render :body</code> will <em>not</em> set the content type header.</li>
|
631
|
+
</ul>
|
632
|
+
<p>From the security standpoint, if you don't expect to have any markup in your
|
633
|
+
response body, you should be using <code>render :plain</code> as most browsers will escape
|
634
|
+
unsafe content in the response for you.</p><p>We will be deprecating the use of <code>render :text</code> in a future version. So please
|
635
|
+
start using the more precise <code>:plain:</code>, <code>:html</code>, and <code>:body</code> options instead.
|
636
|
+
Using <code>render :text</code> may pose a security risk, as the content is sent as
|
637
|
+
<code>text/html</code>.</p><h4 id="postgresql-json-and-hstore-datatypes">3.14 PostgreSQL json and hstore datatypes</h4><p>Rails 4.1 will map <code>json</code> and <code>hstore</code> columns to a string-keyed Ruby <code>Hash</code>.
|
638
|
+
In earlier versions a <code>HashWithIndifferentAccess</code> was used. This means that
|
639
|
+
symbol access is no longer supported. This is also the case for
|
640
|
+
<code>store_accessors</code> based on top of <code>json</code> or <code>hstore</code> columns. Make sure to use
|
641
|
+
string keys consistently.</p><h4 id="explicit-block-use-for-activesupport::callbacks">3.15 Explicit block use for <code>ActiveSupport::Callbacks</code>
|
642
|
+
</h4><p>Rails 4.1 now expects an explicit block to be passed when calling
|
643
|
+
<code>ActiveSupport::Callbacks.set_callback</code>. This change stems from
|
644
|
+
<code>ActiveSupport::Callbacks</code> being largely rewritten for the 4.1 release.</p><div class="code_container">
|
645
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
646
|
+
# Previously in Rails 4.0
|
647
|
+
set_callback :save, :around, ->(r, &block) { stuff; result = block.call; stuff }
|
648
|
+
|
649
|
+
# Now in Rails 4.1
|
650
|
+
set_callback :save, :around, ->(r, block) { stuff; result = block.call; stuff }
|
651
|
+
|
652
|
+
</pre>
|
653
|
+
</div>
|
654
|
+
<h3 id="upgrading-from-rails-3.2-to-rails-4.0">4 Upgrading from Rails 3.2 to Rails 4.0</h3><p>If your application is currently on any version of Rails older than 3.2.x, you should upgrade to Rails 3.2 before attempting one to Rails 4.0.</p><p>The following changes are meant for upgrading your application to Rails 4.0.</p><h4 id="http-patch">4.1 HTTP PATCH</h4><p>Rails 4 now uses <code>PATCH</code> as the primary HTTP verb for updates when a RESTful
|
655
|
+
resource is declared in <code>config/routes.rb</code>. The <code>update</code> action is still used,
|
656
|
+
and <code>PUT</code> requests will continue to be routed to the <code>update</code> action as well.
|
657
|
+
So, if you're using only the standard RESTful routes, no changes need to be made:</p><div class="code_container">
|
658
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
659
|
+
resources :users
|
660
|
+
|
661
|
+
</pre>
|
662
|
+
</div>
|
663
|
+
<div class="code_container">
|
664
|
+
<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
|
665
|
+
<%= form_for @user do |f| %>
|
666
|
+
|
667
|
+
</pre>
|
668
|
+
</div>
|
669
|
+
<div class="code_container">
|
670
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
671
|
+
class UsersController < ApplicationController
|
672
|
+
def update
|
673
|
+
# No change needed; PATCH will be preferred, and PUT will still work.
|
674
|
+
end
|
675
|
+
end
|
676
|
+
|
677
|
+
</pre>
|
678
|
+
</div>
|
679
|
+
<p>However, you will need to make a change if you are using <code>form_for</code> to update
|
680
|
+
a resource in conjunction with a custom route using the <code>PUT</code> HTTP method:</p><div class="code_container">
|
681
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
682
|
+
resources :users, do
|
683
|
+
put :update_name, on: :member
|
684
|
+
end
|
685
|
+
|
686
|
+
</pre>
|
687
|
+
</div>
|
688
|
+
<div class="code_container">
|
689
|
+
<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
|
690
|
+
<%= form_for [ :update_name, @user ] do |f| %>
|
691
|
+
|
692
|
+
</pre>
|
693
|
+
</div>
|
694
|
+
<div class="code_container">
|
695
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
696
|
+
class UsersController < ApplicationController
|
697
|
+
def update_name
|
698
|
+
# Change needed; form_for will try to use a non-existent PATCH route.
|
699
|
+
end
|
700
|
+
end
|
701
|
+
|
702
|
+
</pre>
|
703
|
+
</div>
|
704
|
+
<p>If the action is not being used in a public API and you are free to change the
|
705
|
+
HTTP method, you can update your route to use <code>patch</code> instead of <code>put</code>:</p><p><code>PUT</code> requests to <code>/users/:id</code> in Rails 4 get routed to <code>update</code> as they are
|
706
|
+
today. So, if you have an API that gets real PUT requests it is going to work.
|
707
|
+
The router also routes <code>PATCH</code> requests to <code>/users/:id</code> to the <code>update</code> action.</p><div class="code_container">
|
708
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
709
|
+
resources :users do
|
710
|
+
patch :update_name, on: :member
|
711
|
+
end
|
712
|
+
|
713
|
+
</pre>
|
714
|
+
</div>
|
715
|
+
<p>If the action is being used in a public API and you can't change to HTTP method
|
716
|
+
being used, you can update your form to use the <code>PUT</code> method instead:</p><div class="code_container">
|
717
|
+
<pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
|
718
|
+
<%= form_for [ :update_name, @user ], method: :put do |f| %>
|
719
|
+
|
720
|
+
</pre>
|
721
|
+
</div>
|
722
|
+
<p>For more on PATCH and why this change was made, see <a href="http://weblog.rubyonrails.org/2012/2/26/edge-rails-patch-is-the-new-primary-http-method-for-updates/">this post</a>
|
723
|
+
on the Rails blog.</p><h5 id="a-note-about-media-types">4.1.1 A note about media types</h5><p>The errata for the <code>PATCH</code> verb <a href="http://www.rfc-editor.org/errata_search.php?rfc=5789">specifies that a 'diff' media type should be
|
724
|
+
used with <code>PATCH</code></a>. One
|
725
|
+
such format is <a href="http://tools.ietf.org/html/rfc6902">JSON Patch</a>. While Rails
|
726
|
+
does not support JSON Patch natively, it's easy enough to add support:</p><div class="code_container">
|
727
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
728
|
+
# in your controller
|
729
|
+
def update
|
730
|
+
respond_to do |format|
|
731
|
+
format.json do
|
732
|
+
# perform a partial update
|
733
|
+
@article.update params[:article]
|
734
|
+
end
|
735
|
+
|
736
|
+
format.json_patch do
|
737
|
+
# perform sophisticated change
|
738
|
+
end
|
739
|
+
end
|
740
|
+
end
|
741
|
+
|
742
|
+
# In config/initializers/json_patch.rb:
|
743
|
+
Mime::Type.register 'application/json-patch+json', :json_patch
|
744
|
+
|
745
|
+
</pre>
|
746
|
+
</div>
|
747
|
+
<p>As JSON Patch was only recently made into an RFC, there aren't a lot of great
|
748
|
+
Ruby libraries yet. Aaron Patterson's
|
749
|
+
<a href="https://github.com/tenderlove/hana">hana</a> is one such gem, but doesn't have
|
750
|
+
full support for the last few changes in the specification.</p><h4 id="upgrading-from-rails-3.2-to-rails-4.0-gemfile">4.2 Gemfile</h4><p>Rails 4.0 removed the <code>assets</code> group from Gemfile. You'd need to remove that
|
751
|
+
line from your Gemfile when upgrading. You should also update your application
|
752
|
+
file (in <code>config/application.rb</code>):</p><div class="code_container">
|
753
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
754
|
+
# Require the gems listed in Gemfile, including any gems
|
755
|
+
# you've limited to :test, :development, or :production.
|
756
|
+
Bundler.require(:default, Rails.env)
|
757
|
+
|
758
|
+
</pre>
|
759
|
+
</div>
|
760
|
+
<h4 id="upgrading-from-rails-3.2-to-rails-4.0-vendor/plugins">4.3 vendor/plugins</h4><p>Rails 4.0 no longer supports loading plugins from <code>vendor/plugins</code>. You must replace any plugins by extracting them to gems and adding them to your Gemfile. If you choose not to make them gems, you can move them into, say, <code>lib/my_plugin/*</code> and add an appropriate initializer in <code>config/initializers/my_plugin.rb</code>.</p><h4 id="upgrading-from-rails-3.2-to-rails-4.0-active-record">4.4 Active Record</h4>
|
761
|
+
<ul>
|
762
|
+
<li><p>Rails 4.0 has removed the identity map from Active Record, due to <a href="https://github.com/rails/rails/commit/302c912bf6bcd0fa200d964ec2dc4a44abe328a6">some inconsistencies with associations</a>. If you have manually enabled it in your application, you will have to remove the following config that has no effect anymore: <code>config.active_record.identity_map</code>.</p></li>
|
763
|
+
<li><p>The <code>delete</code> method in collection associations can now receive <code>Fixnum</code> or <code>String</code> arguments as record ids, besides records, pretty much like the <code>destroy</code> method does. Previously it raised <code>ActiveRecord::AssociationTypeMismatch</code> for such arguments. From Rails 4.0 on <code>delete</code> automatically tries to find the records matching the given ids before deleting them.</p></li>
|
764
|
+
<li><p>In Rails 4.0 when a column or a table is renamed the related indexes are also renamed. If you have migrations which rename the indexes, they are no longer needed.</p></li>
|
765
|
+
<li><p>Rails 4.0 has changed <code>serialized_attributes</code> and <code>attr_readonly</code> to class methods only. You shouldn't use instance methods since it's now deprecated. You should change them to use class methods, e.g. <code>self.serialized_attributes</code> to <code>self.class.serialized_attributes</code>.</p></li>
|
766
|
+
<li><p>When using the default coder, assigning <code>nil</code> to a serialized attribute will save it
|
767
|
+
to the database as <code>NULL</code> instead of passing the <code>nil</code> value through YAML (<code>"--- \n...\n"</code>).</p></li>
|
768
|
+
<li><p>Rails 4.0 has removed <code>attr_accessible</code> and <code>attr_protected</code> feature in favor of Strong Parameters. You can use the <a href="https://github.com/rails/protected_attributes">Protected Attributes gem</a> for a smooth upgrade path.</p></li>
|
769
|
+
<li><p>If you are not using Protected Attributes, you can remove any options related to
|
770
|
+
this gem such as <code>whitelist_attributes</code> or <code>mass_assignment_sanitizer</code> options.</p></li>
|
771
|
+
<li><p>Rails 4.0 requires that scopes use a callable object such as a Proc or lambda:</p></li>
|
772
|
+
</ul>
|
773
|
+
<div class="code_container">
|
774
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
775
|
+
scope :active, where(active: true)
|
776
|
+
|
777
|
+
# becomes
|
778
|
+
scope :active, -> { where active: true }
|
779
|
+
|
780
|
+
</pre>
|
781
|
+
</div>
|
782
|
+
|
783
|
+
<ul>
|
784
|
+
<li><p>Rails 4.0 has deprecated <code>ActiveRecord::Fixtures</code> in favor of <code>ActiveRecord::FixtureSet</code>.</p></li>
|
785
|
+
<li><p>Rails 4.0 has deprecated <code>ActiveRecord::TestCase</code> in favor of <code>ActiveSupport::TestCase</code>.</p></li>
|
786
|
+
<li><p>Rails 4.0 has deprecated the old-style hash based finder API. This means that
|
787
|
+
methods which previously accepted "finder options" no longer do.</p></li>
|
788
|
+
<li>
|
789
|
+
<p>All dynamic methods except for <code>find_by_...</code> and <code>find_by_...!</code> are deprecated.
|
790
|
+
Here's how you can handle the changes:</p>
|
791
|
+
<ul>
|
792
|
+
<li>
|
793
|
+
<code>find_all_by_...</code> becomes <code>where(...)</code>.</li>
|
794
|
+
<li>
|
795
|
+
<code>find_last_by_...</code> becomes <code>where(...).last</code>.</li>
|
796
|
+
<li>
|
797
|
+
<code>scoped_by_...</code> becomes <code>where(...)</code>.</li>
|
798
|
+
<li>
|
799
|
+
<code>find_or_initialize_by_...</code> becomes <code>find_or_initialize_by(...)</code>.</li>
|
800
|
+
<li>
|
801
|
+
<code>find_or_create_by_...</code> becomes <code>find_or_create_by(...)</code>.</li>
|
802
|
+
</ul>
|
803
|
+
</li>
|
804
|
+
<li><p>Note that <code>where(...)</code> returns a relation, not an array like the old finders. If you require an <code>Array</code>, use <code>where(...).to_a</code>.</p></li>
|
805
|
+
<li><p>These equivalent methods may not execute the same SQL as the previous implementation.</p></li>
|
806
|
+
<li><p>To re-enable the old finders, you can use the <a href="https://github.com/rails/activerecord-deprecated_finders">activerecord-deprecated_finders gem</a>.</p></li>
|
807
|
+
</ul>
|
808
|
+
<h4 id="active-resource">4.5 Active Resource</h4><p>Rails 4.0 extracted Active Resource to its own gem. If you still need the feature you can add the <a href="https://github.com/rails/activeresource">Active Resource gem</a> in your Gemfile.</p><h4 id="active-model">4.6 Active Model</h4>
|
809
|
+
<ul>
|
810
|
+
<li><p>Rails 4.0 has changed how errors attach with the <code>ActiveModel::Validations::ConfirmationValidator</code>. Now when confirmation validations fail, the error will be attached to <code>:#{attribute}_confirmation</code> instead of <code>attribute</code>.</p></li>
|
811
|
+
<li><p>Rails 4.0 has changed <code>ActiveModel::Serializers::JSON.include_root_in_json</code> default value to <code>false</code>. Now, Active Model Serializers and Active Record objects have the same default behaviour. This means that you can comment or remove the following option in the <code>config/initializers/wrap_parameters.rb</code> file:</p></li>
|
812
|
+
</ul>
|
813
|
+
<div class="code_container">
|
814
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
815
|
+
# Disable root element in JSON by default.
|
816
|
+
# ActiveSupport.on_load(:active_record) do
|
817
|
+
# self.include_root_in_json = false
|
818
|
+
# end
|
819
|
+
|
820
|
+
</pre>
|
821
|
+
</div>
|
822
|
+
<h4 id="action-pack">4.7 Action Pack</h4>
|
823
|
+
<ul>
|
824
|
+
<li>Rails 4.0 introduces <code>ActiveSupport::KeyGenerator</code> and uses this as a base from which to generate and verify signed cookies (among other things). Existing signed cookies generated with Rails 3.x will be transparently upgraded if you leave your existing <code>secret_token</code> in place and add the new <code>secret_key_base</code>.</li>
|
825
|
+
</ul>
|
826
|
+
<div class="code_container">
|
827
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
828
|
+
# config/initializers/secret_token.rb
|
829
|
+
Myapp::Application.config.secret_token = 'existing secret token'
|
830
|
+
Myapp::Application.config.secret_key_base = 'new secret key base'
|
831
|
+
|
832
|
+
</pre>
|
833
|
+
</div>
|
834
|
+
<p>Please note that you should wait to set <code>secret_key_base</code> until you have 100% of your userbase on Rails 4.x and are reasonably sure you will not need to rollback to Rails 3.x. This is because cookies signed based on the new <code>secret_key_base</code> in Rails 4.x are not backwards compatible with Rails 3.x. You are free to leave your existing <code>secret_token</code> in place, not set the new <code>secret_key_base</code>, and ignore the deprecation warnings until you are reasonably sure that your upgrade is otherwise complete.</p><p>If you are relying on the ability for external applications or Javascript to be able to read your Rails app's signed session cookies (or signed cookies in general) you should not set <code>secret_key_base</code> until you have decoupled these concerns.</p>
|
835
|
+
<ul>
|
836
|
+
<li>Rails 4.0 encrypts the contents of cookie-based sessions if <code>secret_key_base</code> has been set. Rails 3.x signed, but did not encrypt, the contents of cookie-based session. Signed cookies are "secure" in that they are verified to have been generated by your app and are tamper-proof. However, the contents can be viewed by end users, and encrypting the contents eliminates this caveat/concern without a significant performance penalty.</li>
|
837
|
+
</ul>
|
838
|
+
<p>Please read <a href="https://github.com/rails/rails/pull/9978">Pull Request #9978</a> for details on the move to encrypted session cookies.</p>
|
839
|
+
<ul>
|
840
|
+
<li><p>Rails 4.0 removed the <code>ActionController::Base.asset_path</code> option. Use the assets pipeline feature.</p></li>
|
841
|
+
<li><p>Rails 4.0 has deprecated <code>ActionController::Base.page_cache_extension</code> option. Use <code>ActionController::Base.default_static_extension</code> instead.</p></li>
|
842
|
+
<li><p>Rails 4.0 has removed Action and Page caching from Action Pack. You will need to add the <code>actionpack-action_caching</code> gem in order to use <code>caches_action</code> and the <code>actionpack-page_caching</code> to use <code>caches_pages</code> in your controllers.</p></li>
|
843
|
+
<li><p>Rails 4.0 has removed the XML parameters parser. You will need to add the <code>actionpack-xml_parser</code> gem if you require this feature.</p></li>
|
844
|
+
<li><p>Rails 4.0 changes the default memcached client from <code>memcache-client</code> to <code>dalli</code>. To upgrade, simply add <code>gem 'dalli'</code> to your <code>Gemfile</code>.</p></li>
|
845
|
+
<li><p>Rails 4.0 deprecates the <code>dom_id</code> and <code>dom_class</code> methods in controllers (they are fine in views). You will need to include the <code>ActionView::RecordIdentifier</code> module in controllers requiring this feature.</p></li>
|
846
|
+
<li><p>Rails 4.0 deprecates the <code>:confirm</code> option for the <code>link_to</code> helper. You should
|
847
|
+
instead rely on a data attribute (e.g. <code>data: { confirm: 'Are you sure?' }</code>).
|
848
|
+
This deprecation also concerns the helpers based on this one (such as <code>link_to_if</code>
|
849
|
+
or <code>link_to_unless</code>).</p></li>
|
850
|
+
<li><p>Rails 4.0 changed how <code>assert_generates</code>, <code>assert_recognizes</code>, and <code>assert_routing</code> work. Now all these assertions raise <code>Assertion</code> instead of <code>ActionController::RoutingError</code>.</p></li>
|
851
|
+
<li><p>Rails 4.0 raises an <code>ArgumentError</code> if clashing named routes are defined. This can be triggered by explicitly defined named routes or by the <code>resources</code> method. Here are two examples that clash with routes named <code>example_path</code>:</p></li>
|
852
|
+
</ul>
|
853
|
+
<div class="code_container">
|
854
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
855
|
+
get 'one' => 'test#example', as: :example
|
856
|
+
get 'two' => 'test#example', as: :example
|
857
|
+
|
858
|
+
</pre>
|
859
|
+
</div>
|
860
|
+
<div class="code_container">
|
861
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
862
|
+
resources :examples
|
863
|
+
get 'clashing/:id' => 'test#example', as: :example
|
864
|
+
|
865
|
+
</pre>
|
866
|
+
</div>
|
867
|
+
<p>In the first case, you can simply avoid using the same name for multiple
|
868
|
+
routes. In the second, you can use the <code>only</code> or <code>except</code> options provided by
|
869
|
+
the <code>resources</code> method to restrict the routes created as detailed in the
|
870
|
+
<a href="routing.html#restricting-the-routes-created">Routing Guide</a>.</p>
|
871
|
+
<ul>
|
872
|
+
<li>Rails 4.0 also changed the way unicode character routes are drawn. Now you can draw unicode character routes directly. If you already draw such routes, you must change them, for example:</li>
|
873
|
+
</ul>
|
874
|
+
<div class="code_container">
|
875
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
876
|
+
get Rack::Utils.escape('こんにちは'), controller: 'welcome', action: 'index'
|
877
|
+
|
878
|
+
</pre>
|
879
|
+
</div>
|
880
|
+
<p>becomes</p><div class="code_container">
|
881
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
882
|
+
get 'こんにちは', controller: 'welcome', action: 'index'
|
883
|
+
|
884
|
+
</pre>
|
885
|
+
</div>
|
886
|
+
|
887
|
+
<ul>
|
888
|
+
<li>Rails 4.0 requires that routes using <code>match</code> must specify the request method. For example:</li>
|
889
|
+
</ul>
|
890
|
+
<div class="code_container">
|
891
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
892
|
+
# Rails 3.x
|
893
|
+
match '/' => 'root#index'
|
894
|
+
|
895
|
+
# becomes
|
896
|
+
match '/' => 'root#index', via: :get
|
897
|
+
|
898
|
+
# or
|
899
|
+
get '/' => 'root#index'
|
900
|
+
|
901
|
+
</pre>
|
902
|
+
</div>
|
903
|
+
|
904
|
+
<ul>
|
905
|
+
<li>Rails 4.0 has removed <code>ActionDispatch::BestStandardsSupport</code> middleware, <code><!DOCTYPE html></code> already triggers standards mode per <a href="http://msdn.microsoft.com/en-us/library/jj676915(v=vs.85).aspx">http://msdn.microsoft.com/en-us/library/jj676915(v=vs.85).aspx</a> and ChromeFrame header has been moved to <code>config.action_dispatch.default_headers</code>.</li>
|
906
|
+
</ul>
|
907
|
+
<p>Remember you must also remove any references to the middleware from your application code, for example:</p><div class="code_container">
|
908
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
909
|
+
# Raise exception
|
910
|
+
config.middleware.insert_before(Rack::Lock, ActionDispatch::BestStandardsSupport)
|
911
|
+
|
912
|
+
</pre>
|
913
|
+
</div>
|
914
|
+
<p>Also check your environment settings for <code>config.action_dispatch.best_standards_support</code> and remove it if present.</p>
|
915
|
+
<ul>
|
916
|
+
<li><p>In Rails 4.0, precompiling assets no longer automatically copies non-JS/CSS assets from <code>vendor/assets</code> and <code>lib/assets</code>. Rails application and engine developers should put these assets in <code>app/assets</code> or configure <code>config.assets.precompile</code>.</p></li>
|
917
|
+
<li><p>In Rails 4.0, <code>ActionController::UnknownFormat</code> is raised when the action doesn't handle the request format. By default, the exception is handled by responding with 406 Not Acceptable, but you can override that now. In Rails 3, 406 Not Acceptable was always returned. No overrides.</p></li>
|
918
|
+
<li><p>In Rails 4.0, a generic <code>ActionDispatch::ParamsParser::ParseError</code> exception is raised when <code>ParamsParser</code> fails to parse request params. You will want to rescue this exception instead of the low-level <code>MultiJson::DecodeError</code>, for example.</p></li>
|
919
|
+
<li><p>In Rails 4.0, <code>SCRIPT_NAME</code> is properly nested when engines are mounted on an app that's served from a URL prefix. You no longer have to set <code>default_url_options[:script_name]</code> to work around overwritten URL prefixes.</p></li>
|
920
|
+
<li><p>Rails 4.0 deprecated <code>ActionController::Integration</code> in favor of <code>ActionDispatch::Integration</code>.</p></li>
|
921
|
+
<li><p>Rails 4.0 deprecated <code>ActionController::IntegrationTest</code> in favor of <code>ActionDispatch::IntegrationTest</code>.</p></li>
|
922
|
+
<li><p>Rails 4.0 deprecated <code>ActionController::PerformanceTest</code> in favor of <code>ActionDispatch::PerformanceTest</code>.</p></li>
|
923
|
+
<li><p>Rails 4.0 deprecated <code>ActionController::AbstractRequest</code> in favor of <code>ActionDispatch::Request</code>.</p></li>
|
924
|
+
<li><p>Rails 4.0 deprecated <code>ActionController::Request</code> in favor of <code>ActionDispatch::Request</code>.</p></li>
|
925
|
+
<li><p>Rails 4.0 deprecated <code>ActionController::AbstractResponse</code> in favor of <code>ActionDispatch::Response</code>.</p></li>
|
926
|
+
<li><p>Rails 4.0 deprecated <code>ActionController::Response</code> in favor of <code>ActionDispatch::Response</code>.</p></li>
|
927
|
+
<li><p>Rails 4.0 deprecated <code>ActionController::Routing</code> in favor of <code>ActionDispatch::Routing</code>.</p></li>
|
928
|
+
</ul>
|
929
|
+
<h4 id="active-support">4.8 Active Support</h4><p>Rails 4.0 removes the <code>j</code> alias for <code>ERB::Util#json_escape</code> since <code>j</code> is already used for <code>ActionView::Helpers::JavaScriptHelper#escape_javascript</code>.</p><h4 id="helpers-loading-order">4.9 Helpers Loading Order</h4><p>The order in which helpers from more than one directory are loaded has changed in Rails 4.0. Previously, they were gathered and then sorted alphabetically. After upgrading to Rails 4.0, helpers will preserve the order of loaded directories and will be sorted alphabetically only within each directory. Unless you explicitly use the <code>helpers_path</code> parameter, this change will only impact the way of loading helpers from engines. If you rely on the ordering, you should check if correct methods are available after upgrade. If you would like to change the order in which engines are loaded, you can use <code>config.railties_order=</code> method.</p><h4 id="active-record-observer-and-action-controller-sweeper">4.10 Active Record Observer and Action Controller Sweeper</h4><p>Active Record Observer and Action Controller Sweeper have been extracted to the <code>rails-observers</code> gem. You will need to add the <code>rails-observers</code> gem if you require these features.</p><h4 id="sprockets-rails">4.11 sprockets-rails</h4>
|
930
|
+
<ul>
|
931
|
+
<li>
|
932
|
+
<code>assets:precompile:primary</code> and <code>assets:precompile:all</code> have been removed. Use <code>assets:precompile</code> instead.</li>
|
933
|
+
<li>The <code>config.assets.compress</code> option should be changed to <code>config.assets.js_compressor</code> like so for instance:</li>
|
934
|
+
</ul>
|
935
|
+
<div class="code_container">
|
936
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
937
|
+
config.assets.js_compressor = :uglifier
|
938
|
+
|
939
|
+
</pre>
|
940
|
+
</div>
|
941
|
+
<h4 id="sass-rails">4.12 sass-rails</h4>
|
942
|
+
<ul>
|
943
|
+
<li>
|
944
|
+
<code>asset-url</code> with two arguments is deprecated. For example: <code>asset-url("rails.png", image)</code> becomes <code>asset-url("rails.png")</code>.</li>
|
945
|
+
</ul>
|
946
|
+
<h3 id="upgrading-from-rails-3.1-to-rails-3.2">5 Upgrading from Rails 3.1 to Rails 3.2</h3><p>If your application is currently on any version of Rails older than 3.1.x, you
|
947
|
+
should upgrade to Rails 3.1 before attempting an update to Rails 3.2.</p><p>The following changes are meant for upgrading your application to the latest
|
948
|
+
3.2.x version of Rails.</p><h4 id="upgrading-from-rails-3.1-to-rails-3.2-gemfile">5.1 Gemfile</h4><p>Make the following changes to your <code>Gemfile</code>.</p><div class="code_container">
|
949
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
950
|
+
gem 'rails', '3.2.18'
|
951
|
+
|
952
|
+
group :assets do
|
953
|
+
gem 'sass-rails', '~> 3.2.6'
|
954
|
+
gem 'coffee-rails', '~> 3.2.2'
|
955
|
+
gem 'uglifier', '>= 1.0.3'
|
956
|
+
end
|
957
|
+
|
958
|
+
</pre>
|
959
|
+
</div>
|
960
|
+
<h4 id="upgrading-from-rails-3.1-to-rails-3.2-config/environments/development.rb">5.2 config/environments/development.rb</h4><p>There are a couple of new configuration settings that you should add to your development environment:</p><div class="code_container">
|
961
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
962
|
+
# Raise exception on mass assignment protection for Active Record models
|
963
|
+
config.active_record.mass_assignment_sanitizer = :strict
|
964
|
+
|
965
|
+
# Log the query plan for queries taking more than this (works
|
966
|
+
# with SQLite, MySQL, and PostgreSQL)
|
967
|
+
config.active_record.auto_explain_threshold_in_seconds = 0.5
|
968
|
+
|
969
|
+
</pre>
|
970
|
+
</div>
|
971
|
+
<h4 id="upgrading-from-rails-3.1-to-rails-3.2-config/environments/test.rb">5.3 config/environments/test.rb</h4><p>The <code>mass_assignment_sanitizer</code> configuration setting should also be be added to <code>config/environments/test.rb</code>:</p><div class="code_container">
|
972
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
973
|
+
# Raise exception on mass assignment protection for Active Record models
|
974
|
+
config.active_record.mass_assignment_sanitizer = :strict
|
975
|
+
|
976
|
+
</pre>
|
977
|
+
</div>
|
978
|
+
<h4 id="upgrading-from-rails-3.1-to-rails-3.2-vendor/plugins">5.4 vendor/plugins</h4><p>Rails 3.2 deprecates <code>vendor/plugins</code> and Rails 4.0 will remove them completely. While it's not strictly necessary as part of a Rails 3.2 upgrade, you can start replacing any plugins by extracting them to gems and adding them to your Gemfile. If you choose not to make them gems, you can move them into, say, <code>lib/my_plugin/*</code> and add an appropriate initializer in <code>config/initializers/my_plugin.rb</code>.</p><h4 id="upgrading-from-rails-3.1-to-rails-3.2-active-record">5.5 Active Record</h4><p>Option <code>:dependent => :restrict</code> has been removed from <code>belongs_to</code>. If you want to prevent deleting the object if there are any associated objects, you can set <code>:dependent => :destroy</code> and return <code>false</code> after checking for existence of association from any of the associated object's destroy callbacks.</p><h3 id="upgrading-from-rails-3.0-to-rails-3.1">6 Upgrading from Rails 3.0 to Rails 3.1</h3><p>If your application is currently on any version of Rails older than 3.0.x, you should upgrade to Rails 3.0 before attempting an update to Rails 3.1.</p><p>The following changes are meant for upgrading your application to Rails 3.1.12, the last 3.1.x version of Rails.</p><h4 id="gemfile">6.1 Gemfile</h4><p>Make the following changes to your <code>Gemfile</code>.</p><div class="code_container">
|
979
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
980
|
+
gem 'rails', '3.1.12'
|
981
|
+
gem 'mysql2'
|
982
|
+
|
983
|
+
# Needed for the new asset pipeline
|
984
|
+
group :assets do
|
985
|
+
gem 'sass-rails', '~> 3.1.7'
|
986
|
+
gem 'coffee-rails', '~> 3.1.1'
|
987
|
+
gem 'uglifier', '>= 1.0.3'
|
988
|
+
end
|
989
|
+
|
990
|
+
# jQuery is the default JavaScript library in Rails 3.1
|
991
|
+
gem 'jquery-rails'
|
992
|
+
|
993
|
+
</pre>
|
994
|
+
</div>
|
995
|
+
<h4 id="config/application.rb">6.2 config/application.rb</h4><p>The asset pipeline requires the following additions:</p><div class="code_container">
|
996
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
997
|
+
config.assets.enabled = true
|
998
|
+
config.assets.version = '1.0'
|
999
|
+
|
1000
|
+
</pre>
|
1001
|
+
</div>
|
1002
|
+
<p>If your application is using an "/assets" route for a resource you may want change the prefix used for assets to avoid conflicts:</p><div class="code_container">
|
1003
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
1004
|
+
# Defaults to '/assets'
|
1005
|
+
config.assets.prefix = '/asset-files'
|
1006
|
+
|
1007
|
+
</pre>
|
1008
|
+
</div>
|
1009
|
+
<h4 id="upgrading-from-rails-3.0-to-rails-3.1-config/environments/development.rb">6.3 config/environments/development.rb</h4><p>Remove the RJS setting <code>config.action_view.debug_rjs = true</code>.</p><p>Add these settings if you enable the asset pipeline:</p><div class="code_container">
|
1010
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
1011
|
+
# Do not compress assets
|
1012
|
+
config.assets.compress = false
|
1013
|
+
|
1014
|
+
# Expands the lines which load the assets
|
1015
|
+
config.assets.debug = true
|
1016
|
+
|
1017
|
+
</pre>
|
1018
|
+
</div>
|
1019
|
+
<h4 id="config/environments/production.rb">6.4 config/environments/production.rb</h4><p>Again, most of the changes below are for the asset pipeline. You can read more about these in the <a href="asset_pipeline.html">Asset Pipeline</a> guide.</p><div class="code_container">
|
1020
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
1021
|
+
# Compress JavaScripts and CSS
|
1022
|
+
config.assets.compress = true
|
1023
|
+
|
1024
|
+
# Don't fallback to assets pipeline if a precompiled asset is missed
|
1025
|
+
config.assets.compile = false
|
1026
|
+
|
1027
|
+
# Generate digests for assets URLs
|
1028
|
+
config.assets.digest = true
|
1029
|
+
|
1030
|
+
# Defaults to Rails.root.join("public/assets")
|
1031
|
+
# config.assets.manifest = YOUR_PATH
|
1032
|
+
|
1033
|
+
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
|
1034
|
+
# config.assets.precompile += %w( search.js )
|
1035
|
+
|
1036
|
+
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
|
1037
|
+
# config.force_ssl = true
|
1038
|
+
|
1039
|
+
</pre>
|
1040
|
+
</div>
|
1041
|
+
<h4 id="upgrading-from-rails-3.0-to-rails-3.1-config/environments/test.rb">6.5 config/environments/test.rb</h4><p>You can help test performance with these additions to your test environment:</p><div class="code_container">
|
1042
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
1043
|
+
# Configure static asset server for tests with Cache-Control for performance
|
1044
|
+
config.serve_static_assets = true
|
1045
|
+
config.static_cache_control = 'public, max-age=3600'
|
1046
|
+
|
1047
|
+
</pre>
|
1048
|
+
</div>
|
1049
|
+
<h4 id="config/initializers/wrap_parameters.rb">6.6 config/initializers/wrap_parameters.rb</h4><p>Add this file with the following contents, if you wish to wrap parameters into a nested hash. This is on by default in new applications.</p><div class="code_container">
|
1050
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
1051
|
+
# Be sure to restart your server when you modify this file.
|
1052
|
+
# This file contains settings for ActionController::ParamsWrapper which
|
1053
|
+
# is enabled by default.
|
1054
|
+
|
1055
|
+
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
|
1056
|
+
ActiveSupport.on_load(:action_controller) do
|
1057
|
+
wrap_parameters format: [:json]
|
1058
|
+
end
|
1059
|
+
|
1060
|
+
# Disable root element in JSON by default.
|
1061
|
+
ActiveSupport.on_load(:active_record) do
|
1062
|
+
self.include_root_in_json = false
|
1063
|
+
end
|
1064
|
+
|
1065
|
+
</pre>
|
1066
|
+
</div>
|
1067
|
+
<h4 id="config/initializers/session_store.rb">6.7 config/initializers/session_store.rb</h4><p>You need to change your session key to something new, or remove all sessions:</p><div class="code_container">
|
1068
|
+
<pre class="brush: ruby; gutter: false; toolbar: false">
|
1069
|
+
# in config/initializers/session_store.rb
|
1070
|
+
AppName::Application.config.session_store :cookie_store, key: 'SOMETHINGNEW'
|
1071
|
+
|
1072
|
+
</pre>
|
1073
|
+
</div>
|
1074
|
+
<p>or</p><div class="code_container">
|
1075
|
+
<pre class="brush: plain; gutter: false; toolbar: false">
|
1076
|
+
$ bin/rake db:sessions:clear
|
1077
|
+
|
1078
|
+
</pre>
|
1079
|
+
</div>
|
1080
|
+
<h4 id="remove-:cache-and-:concat-options-in-asset-helpers-references-in-views">6.8 Remove :cache and :concat options in asset helpers references in views</h4>
|
1081
|
+
<ul>
|
1082
|
+
<li>With the Asset Pipeline the :cache and :concat options aren't used anymore, delete these options from your views.</li>
|
1083
|
+
</ul>
|
1084
|
+
|
1085
|
+
|
1086
|
+
<h3>Feedback</h3>
|
1087
|
+
<p>
|
1088
|
+
You're encouraged to help improve the quality of this guide.
|
1089
|
+
</p>
|
1090
|
+
<p>
|
1091
|
+
Please contribute if you see any typos or factual errors.
|
1092
|
+
To get started, you can read our <a href="http://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html#contributing-to-the-rails-documentation">documentation contributions</a> section.
|
1093
|
+
</p>
|
1094
|
+
<p>
|
1095
|
+
You may also find incomplete content, or stuff that is not up to date.
|
1096
|
+
Please do add any missing documentation for master. Make sure to check
|
1097
|
+
<a href="http://edgeguides.rubyonrails.org">Edge Guides</a> first to verify
|
1098
|
+
if the issues are already fixed or not on the master branch.
|
1099
|
+
Check the <a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a>
|
1100
|
+
for style and conventions.
|
1101
|
+
</p>
|
1102
|
+
<p>
|
1103
|
+
If for whatever reason you spot something to fix but cannot patch it yourself, please
|
1104
|
+
<a href="https://github.com/rails/rails/issues">open an issue</a>.
|
1105
|
+
</p>
|
1106
|
+
<p>And last but not least, any kind of discussion regarding Ruby on Rails
|
1107
|
+
documentation is very welcome in the <a href="http://groups.google.com/group/rubyonrails-docs">rubyonrails-docs mailing list</a>.
|
1108
|
+
</p>
|
1109
|
+
</div>
|
1110
|
+
</div>
|
1111
|
+
</div>
|
1112
|
+
|
1113
|
+
<hr class="hide" />
|
1114
|
+
<div id="footer">
|
1115
|
+
<div class="wrapper">
|
1116
|
+
<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>
|
1117
|
+
<p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
|
1118
|
+
|
1119
|
+
</div>
|
1120
|
+
</div>
|
1121
|
+
|
1122
|
+
<script type="text/javascript" src="javascripts/jquery.min.js"></script>
|
1123
|
+
<script type="text/javascript" src="javascripts/responsive-tables.js"></script>
|
1124
|
+
<script type="text/javascript" src="javascripts/guides.js"></script>
|
1125
|
+
<script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
|
1126
|
+
<script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
|
1127
|
+
<script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
|
1128
|
+
<script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
|
1129
|
+
<script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
|
1130
|
+
<script type="text/javascript">
|
1131
|
+
SyntaxHighlighter.all();
|
1132
|
+
$(guidesIndex.bind);
|
1133
|
+
</script>
|
1134
|
+
</body>
|
1135
|
+
</html>
|