rails_test 4.2.0.beta1

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