rails 4.1.14.2 → 4.2.11.1
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.
- checksums.yaml +5 -5
- data/README.md +12 -10
- data/guides/CHANGELOG.md +34 -37
- data/guides/Rakefile +21 -6
- data/guides/assets/images/getting_started/article_with_comments.png +0 -0
- data/guides/assets/javascripts/guides.js +6 -0
- data/guides/assets/stylesheets/main.css +4 -1
- data/guides/bug_report_templates/action_controller_gem.rb +1 -1
- data/guides/bug_report_templates/action_controller_master.rb +1 -0
- data/guides/bug_report_templates/active_record_gem.rb +1 -1
- data/guides/bug_report_templates/generic_gem.rb +1 -1
- data/guides/rails_guides/helpers.rb +1 -1
- data/guides/rails_guides/levenshtein.rb +27 -21
- data/guides/rails_guides/markdown/renderer.rb +1 -1
- data/guides/rails_guides/markdown.rb +11 -7
- data/guides/rails_guides.rb +2 -2
- data/guides/source/2_2_release_notes.md +1 -1
- data/guides/source/2_3_release_notes.md +4 -4
- data/guides/source/3_0_release_notes.md +8 -8
- data/guides/source/3_1_release_notes.md +5 -2
- data/guides/source/3_2_release_notes.md +6 -3
- data/guides/source/4_0_release_notes.md +6 -3
- data/guides/source/4_1_release_notes.md +5 -6
- data/guides/source/4_2_release_notes.md +877 -0
- data/guides/source/_license.html.erb +1 -1
- data/guides/source/_welcome.html.erb +6 -8
- data/guides/source/action_controller_overview.md +25 -8
- data/guides/source/action_mailer_basics.md +97 -29
- data/guides/source/action_view_overview.md +142 -183
- data/guides/source/active_job_basics.md +339 -0
- data/guides/source/active_model_basics.md +371 -17
- data/guides/source/active_record_basics.md +25 -24
- data/guides/source/active_record_callbacks.md +12 -9
- data/guides/source/{migrations.md → active_record_migrations.md} +95 -220
- data/guides/source/active_record_postgresql.md +433 -0
- data/guides/source/active_record_querying.md +264 -268
- data/guides/source/active_record_validations.md +23 -13
- data/guides/source/active_support_core_extensions.md +114 -75
- data/guides/source/active_support_instrumentation.md +10 -18
- data/guides/source/api_documentation_guidelines.md +63 -17
- data/guides/source/asset_pipeline.md +258 -119
- data/guides/source/association_basics.md +96 -80
- data/guides/source/autoloading_and_reloading_constants.md +1311 -0
- data/guides/source/caching_with_rails.md +32 -7
- data/guides/source/command_line.md +52 -30
- data/guides/source/configuring.md +161 -33
- data/guides/source/contributing_to_ruby_on_rails.md +198 -114
- data/guides/source/credits.html.erb +2 -2
- data/guides/source/debugging_rails_applications.md +440 -286
- data/guides/source/development_dependencies_install.md +47 -36
- data/guides/source/documents.yaml +19 -7
- data/guides/source/engines.md +189 -189
- data/guides/source/form_helpers.md +79 -56
- data/guides/source/generators.md +24 -11
- data/guides/source/getting_started.md +359 -219
- data/guides/source/i18n.md +110 -66
- data/guides/source/index.html.erb +1 -0
- data/guides/source/initialization.md +109 -62
- data/guides/source/layout.html.erb +5 -11
- data/guides/source/layouts_and_rendering.md +26 -26
- data/guides/source/maintenance_policy.md +6 -3
- data/guides/source/nested_model_forms.md +7 -4
- data/guides/source/plugins.md +27 -27
- data/guides/source/rails_application_templates.md +21 -3
- data/guides/source/rails_on_rack.md +8 -5
- data/guides/source/routing.md +113 -73
- data/guides/source/ruby_on_rails_guides_guidelines.md +11 -12
- data/guides/source/security.md +39 -33
- data/guides/source/testing.md +199 -119
- data/guides/source/upgrading_ruby_on_rails.md +287 -29
- data/guides/source/working_with_javascript_in_rails.md +19 -17
- data/guides/w3c_validator.rb +2 -0
- metadata +40 -95
- data/guides/code/getting_started/Gemfile +0 -40
- data/guides/code/getting_started/Gemfile.lock +0 -125
- data/guides/code/getting_started/README.rdoc +0 -28
- data/guides/code/getting_started/Rakefile +0 -6
- data/guides/code/getting_started/app/assets/javascripts/application.js +0 -15
- data/guides/code/getting_started/app/assets/javascripts/comments.js.coffee +0 -3
- data/guides/code/getting_started/app/assets/javascripts/posts.js.coffee +0 -3
- data/guides/code/getting_started/app/assets/javascripts/welcome.js.coffee +0 -3
- data/guides/code/getting_started/app/assets/stylesheets/application.css +0 -13
- data/guides/code/getting_started/app/assets/stylesheets/comments.css.scss +0 -3
- data/guides/code/getting_started/app/assets/stylesheets/posts.css.scss +0 -3
- data/guides/code/getting_started/app/assets/stylesheets/welcome.css.scss +0 -3
- data/guides/code/getting_started/app/controllers/application_controller.rb +0 -5
- data/guides/code/getting_started/app/controllers/comments_controller.rb +0 -23
- data/guides/code/getting_started/app/controllers/posts_controller.rb +0 -53
- data/guides/code/getting_started/app/controllers/welcome_controller.rb +0 -4
- data/guides/code/getting_started/app/helpers/application_helper.rb +0 -2
- data/guides/code/getting_started/app/helpers/comments_helper.rb +0 -2
- data/guides/code/getting_started/app/helpers/posts_helper.rb +0 -2
- data/guides/code/getting_started/app/helpers/welcome_helper.rb +0 -2
- data/guides/code/getting_started/app/models/comment.rb +0 -3
- data/guides/code/getting_started/app/models/post.rb +0 -7
- data/guides/code/getting_started/app/views/comments/_comment.html.erb +0 -15
- data/guides/code/getting_started/app/views/comments/_form.html.erb +0 -13
- data/guides/code/getting_started/app/views/layouts/application.html.erb +0 -14
- data/guides/code/getting_started/app/views/posts/_form.html.erb +0 -27
- data/guides/code/getting_started/app/views/posts/edit.html.erb +0 -5
- data/guides/code/getting_started/app/views/posts/index.html.erb +0 -21
- data/guides/code/getting_started/app/views/posts/new.html.erb +0 -5
- data/guides/code/getting_started/app/views/posts/show.html.erb +0 -18
- data/guides/code/getting_started/app/views/welcome/index.html.erb +0 -4
- data/guides/code/getting_started/bin/bundle +0 -4
- data/guides/code/getting_started/bin/rails +0 -4
- data/guides/code/getting_started/bin/rake +0 -4
- data/guides/code/getting_started/config/application.rb +0 -18
- data/guides/code/getting_started/config/boot.rb +0 -4
- data/guides/code/getting_started/config/database.yml +0 -25
- data/guides/code/getting_started/config/environment.rb +0 -5
- data/guides/code/getting_started/config/environments/development.rb +0 -30
- data/guides/code/getting_started/config/environments/production.rb +0 -80
- data/guides/code/getting_started/config/environments/test.rb +0 -36
- data/guides/code/getting_started/config/initializers/backtrace_silencers.rb +0 -7
- data/guides/code/getting_started/config/initializers/filter_parameter_logging.rb +0 -4
- data/guides/code/getting_started/config/initializers/inflections.rb +0 -16
- data/guides/code/getting_started/config/initializers/locale.rb +0 -9
- data/guides/code/getting_started/config/initializers/mime_types.rb +0 -5
- data/guides/code/getting_started/config/initializers/secret_token.rb +0 -12
- data/guides/code/getting_started/config/initializers/session_store.rb +0 -3
- data/guides/code/getting_started/config/initializers/wrap_parameters.rb +0 -14
- data/guides/code/getting_started/config/locales/en.yml +0 -23
- data/guides/code/getting_started/config/routes.rb +0 -7
- data/guides/code/getting_started/config.ru +0 -4
- data/guides/code/getting_started/db/migrate/20130122042648_create_posts.rb +0 -10
- data/guides/code/getting_started/db/migrate/20130122045842_create_comments.rb +0 -11
- data/guides/code/getting_started/db/schema.rb +0 -33
- data/guides/code/getting_started/db/seeds.rb +0 -7
- data/guides/code/getting_started/public/404.html +0 -60
- data/guides/code/getting_started/public/422.html +0 -60
- data/guides/code/getting_started/public/500.html +0 -59
- data/guides/code/getting_started/public/favicon.ico +0 -0
- data/guides/code/getting_started/public/robots.txt +0 -5
- data/guides/code/getting_started/test/controllers/comments_controller_test.rb +0 -7
- data/guides/code/getting_started/test/controllers/posts_controller_test.rb +0 -7
- data/guides/code/getting_started/test/controllers/welcome_controller_test.rb +0 -9
- data/guides/code/getting_started/test/fixtures/comments.yml +0 -11
- data/guides/code/getting_started/test/fixtures/posts.yml +0 -9
- data/guides/code/getting_started/test/helpers/comments_helper_test.rb +0 -4
- data/guides/code/getting_started/test/helpers/posts_helper_test.rb +0 -4
- data/guides/code/getting_started/test/helpers/welcome_helper_test.rb +0 -4
- data/guides/code/getting_started/test/models/comment_test.rb +0 -7
- data/guides/code/getting_started/test/models/post_test.rb +0 -7
- data/guides/code/getting_started/test/test_helper.rb +0 -12
|
@@ -8,7 +8,7 @@ This guide provides steps to be followed when you upgrade your applications to a
|
|
|
8
8
|
General Advice
|
|
9
9
|
--------------
|
|
10
10
|
|
|
11
|
-
Before attempting to upgrade an existing application, you should be sure you have a good reason to upgrade. You need to balance
|
|
11
|
+
Before attempting to upgrade an existing application, you should be sure you have a good reason to upgrade. You need to balance several factors: the need for new features, the increasing difficulty of finding support for old code, and your available time and skills, to name a few.
|
|
12
12
|
|
|
13
13
|
### Test Coverage
|
|
14
14
|
|
|
@@ -24,6 +24,246 @@ Rails generally stays close to the latest released Ruby version when it's releas
|
|
|
24
24
|
|
|
25
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
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 an
|
|
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
|
+
### Web Console
|
|
54
|
+
|
|
55
|
+
First, add `gem 'web-console', '~> 2.0'` to the `:development` group in your Gemfile and run `bundle install` (it won't have been included when you upgraded Rails). Once it's been installed, you can simply drop a reference to the console helper (i.e., `<%= console %>`) into any view you want to enable it for. A console will also be provided on any error page you view in your development environment.
|
|
56
|
+
|
|
57
|
+
### Responders
|
|
58
|
+
|
|
59
|
+
`respond_with` and the class-level `respond_to` methods have been extracted to the `responders` gem. To use them, simply add `gem 'responders', '~> 2.0'` to your Gemfile. Calls to `respond_with` and `respond_to` (again, at the class level) will no longer work without having included the `responders` gem in your dependencies:
|
|
60
|
+
|
|
61
|
+
```ruby
|
|
62
|
+
# app/controllers/users_controller.rb
|
|
63
|
+
|
|
64
|
+
class UsersController < ApplicationController
|
|
65
|
+
respond_to :html, :json
|
|
66
|
+
|
|
67
|
+
def show
|
|
68
|
+
@user = User.find(params[:id])
|
|
69
|
+
respond_with @user
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Instance-level `respond_to` is unaffected and does not require the additional gem:
|
|
75
|
+
|
|
76
|
+
```ruby
|
|
77
|
+
# app/controllers/users_controller.rb
|
|
78
|
+
|
|
79
|
+
class UsersController < ApplicationController
|
|
80
|
+
def show
|
|
81
|
+
@user = User.find(params[:id])
|
|
82
|
+
respond_to do |format|
|
|
83
|
+
format.html
|
|
84
|
+
format.json { render json: @user }
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
See [#16526](https://github.com/rails/rails/pull/16526) for more details.
|
|
91
|
+
|
|
92
|
+
### Error handling in transaction callbacks
|
|
93
|
+
|
|
94
|
+
Currently, Active Record suppresses errors raised
|
|
95
|
+
within `after_rollback` or `after_commit` callbacks and only prints them to
|
|
96
|
+
the logs. In the next version, these errors will no longer be suppressed.
|
|
97
|
+
Instead, the errors will propagate normally just like in other Active
|
|
98
|
+
Record callbacks.
|
|
99
|
+
|
|
100
|
+
When you define a `after_rollback` or `after_commit` callback, you
|
|
101
|
+
will receive a deprecation warning about this upcoming change. When
|
|
102
|
+
you are ready, you can opt into the new behavior and remove the
|
|
103
|
+
deprecation warning by adding following configuration to your
|
|
104
|
+
`config/application.rb`:
|
|
105
|
+
|
|
106
|
+
config.active_record.raise_in_transactional_callbacks = true
|
|
107
|
+
|
|
108
|
+
See [#14488](https://github.com/rails/rails/pull/14488) and
|
|
109
|
+
[#16537](https://github.com/rails/rails/pull/16537) for more details.
|
|
110
|
+
|
|
111
|
+
### Ordering of test cases
|
|
112
|
+
|
|
113
|
+
In Rails 5.0, test cases will be executed in random order by default. In
|
|
114
|
+
anticipation of this change, Rails 4.2 introduced a new configuration option
|
|
115
|
+
`active_support.test_order` for explicitly specifying the test ordering. This
|
|
116
|
+
allows you to either lock down the current behavior by setting the option to
|
|
117
|
+
`:sorted`, or opt into the future behavior by setting the option to `:random`.
|
|
118
|
+
|
|
119
|
+
If you do not specify a value for this option, a deprecation warning will be
|
|
120
|
+
emitted. To avoid this, add the following line to your test environment:
|
|
121
|
+
|
|
122
|
+
```ruby
|
|
123
|
+
# config/environments/test.rb
|
|
124
|
+
Rails.application.configure do
|
|
125
|
+
config.active_support.test_order = :sorted # or `:random` if you prefer
|
|
126
|
+
end
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Serialized attributes
|
|
130
|
+
|
|
131
|
+
When using a custom coder (e.g. `serialize :metadata, JSON`),
|
|
132
|
+
assigning `nil` to a serialized attribute will save it to the database
|
|
133
|
+
as `NULL` instead of passing the `nil` value through the coder (e.g. `"null"`
|
|
134
|
+
when using the `JSON` coder).
|
|
135
|
+
|
|
136
|
+
### Production log level
|
|
137
|
+
|
|
138
|
+
In Rails 5, the default log level for the production environment will be changed
|
|
139
|
+
to `:debug` (from `:info`). To preserve the current default, add the following
|
|
140
|
+
line to your `production.rb`:
|
|
141
|
+
|
|
142
|
+
```ruby
|
|
143
|
+
# Set to `:info` to match the current default, or set to `:debug` to opt-into
|
|
144
|
+
# the future default.
|
|
145
|
+
config.log_level = :info
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### `after_bundle` in Rails templates
|
|
149
|
+
|
|
150
|
+
If you have a Rails template that adds all the files in version control, it
|
|
151
|
+
fails to add the generated binstubs because it gets executed before Bundler:
|
|
152
|
+
|
|
153
|
+
```ruby
|
|
154
|
+
# template.rb
|
|
155
|
+
generate(:scaffold, "person name:string")
|
|
156
|
+
route "root to: 'people#index'"
|
|
157
|
+
rake("db:migrate")
|
|
158
|
+
|
|
159
|
+
git :init
|
|
160
|
+
git add: "."
|
|
161
|
+
git commit: %Q{ -m 'Initial commit' }
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
You can now wrap the `git` calls in an `after_bundle` block. It will be run
|
|
165
|
+
after the binstubs have been generated.
|
|
166
|
+
|
|
167
|
+
```ruby
|
|
168
|
+
# template.rb
|
|
169
|
+
generate(:scaffold, "person name:string")
|
|
170
|
+
route "root to: 'people#index'"
|
|
171
|
+
rake("db:migrate")
|
|
172
|
+
|
|
173
|
+
after_bundle do
|
|
174
|
+
git :init
|
|
175
|
+
git add: "."
|
|
176
|
+
git commit: %Q{ -m 'Initial commit' }
|
|
177
|
+
end
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Rails HTML Sanitizer
|
|
181
|
+
|
|
182
|
+
There's a new choice for sanitizing HTML fragments in your applications. The
|
|
183
|
+
venerable html-scanner approach is now officially being deprecated in favor of
|
|
184
|
+
[`Rails HTML Sanitizer`](https://github.com/rails/rails-html-sanitizer).
|
|
185
|
+
|
|
186
|
+
This means the methods `sanitize`, `sanitize_css`, `strip_tags` and
|
|
187
|
+
`strip_links` are backed by a new implementation.
|
|
188
|
+
|
|
189
|
+
This new sanitizer uses [Loofah](https://github.com/flavorjones/loofah) internally. Loofah in turn uses Nokogiri, which
|
|
190
|
+
wraps XML parsers written in both C and Java, so sanitization should be faster
|
|
191
|
+
no matter which Ruby version you run.
|
|
192
|
+
|
|
193
|
+
The new version updates `sanitize`, so it can take a `Loofah::Scrubber` for
|
|
194
|
+
powerful scrubbing.
|
|
195
|
+
[See some examples of scrubbers here](https://github.com/flavorjones/loofah#loofahscrubber).
|
|
196
|
+
|
|
197
|
+
Two new scrubbers have also been added: `PermitScrubber` and `TargetScrubber`.
|
|
198
|
+
Read the [gem's readme](https://github.com/rails/rails-html-sanitizer) for more information.
|
|
199
|
+
|
|
200
|
+
The documentation for `PermitScrubber` and `TargetScrubber` explains how you
|
|
201
|
+
can gain complete control over when and how elements should be stripped.
|
|
202
|
+
|
|
203
|
+
If your application needs to use the old sanitizer implementation, include `rails-deprecated_sanitizer` in your Gemfile:
|
|
204
|
+
|
|
205
|
+
```ruby
|
|
206
|
+
gem 'rails-deprecated_sanitizer'
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Rails DOM Testing
|
|
210
|
+
|
|
211
|
+
The [`TagAssertions` module](http://api.rubyonrails.org/classes/ActionDispatch/Assertions/TagAssertions.html) (containing methods such as `assert_tag`), [has been deprecated](https://github.com/rails/rails/blob/6061472b8c310158a2a2e8e9a6b81a1aef6b60fe/actionpack/lib/action_dispatch/testing/assertions/dom.rb) in favor of the `assert_select` methods from the `SelectorAssertions` module, which has been extracted into the [rails-dom-testing gem](https://github.com/rails/rails-dom-testing).
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
### Masked Authenticity Tokens
|
|
215
|
+
|
|
216
|
+
In order to mitigate SSL attacks, `form_authenticity_token` is now masked so that it varies with each request. Thus, tokens are validated by unmasking and then decrypting. As a result, any strategies for verifying requests from non-rails forms that relied on a static session CSRF token have to take this into account.
|
|
217
|
+
|
|
218
|
+
### Action Mailer
|
|
219
|
+
|
|
220
|
+
Previously, calling a mailer method on a mailer class will result in the
|
|
221
|
+
corresponding instance method being executed directly. With the introduction of
|
|
222
|
+
Active Job and `#deliver_later`, this is no longer true. In Rails 4.2, the
|
|
223
|
+
invocation of the instance methods are deferred until either `deliver_now` or
|
|
224
|
+
`deliver_later` is called. For example:
|
|
225
|
+
|
|
226
|
+
```ruby
|
|
227
|
+
class Notifier < ActionMailer::Base
|
|
228
|
+
def notify(user, ...)
|
|
229
|
+
puts "Called"
|
|
230
|
+
mail(to: user.email, ...)
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
mail = Notifier.notify(user, ...) # Notifier#welcome is not yet called at this point
|
|
235
|
+
mail = mail.deliver_now # Prints "Called"
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
This should not result in any noticible differnces for most applications.
|
|
239
|
+
However, if you need some non-mailer methods to be exectuted synchronously, and
|
|
240
|
+
you were previously relying on the synchronous proxying behavior, you should
|
|
241
|
+
define them as class methods on the mailer class directly:
|
|
242
|
+
|
|
243
|
+
```ruby
|
|
244
|
+
class Notifier < ActionMailer::Base
|
|
245
|
+
def self.broadcast_notifications(users, ...)
|
|
246
|
+
users.each { |user| Notifier.notify(user, ...) }
|
|
247
|
+
end
|
|
248
|
+
end
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### Foreign Key Support
|
|
252
|
+
|
|
253
|
+
The migration DSL has been expanded to support foreign key definitions. If
|
|
254
|
+
you've been using the Foreigner gem, you might want to consider removing it.
|
|
255
|
+
Note that the foreign key support of Rails is a subset of Foreigner. This means
|
|
256
|
+
that not every Foreigner definition can be fully replaced by it's Rails
|
|
257
|
+
migration DSL counterpart.
|
|
258
|
+
|
|
259
|
+
The migration procedure is as follows:
|
|
260
|
+
|
|
261
|
+
1. remove `gem "foreigner"` from the Gemfile.
|
|
262
|
+
2. run `bundle install`.
|
|
263
|
+
3. run `bin/rake db:schema:dump`.
|
|
264
|
+
4. make sure that `db/schema.rb` contains every foreign key definition with
|
|
265
|
+
the necessary options.
|
|
266
|
+
|
|
27
267
|
Upgrading from Rails 4.0 to Rails 4.1
|
|
28
268
|
-------------------------------------
|
|
29
269
|
|
|
@@ -32,7 +272,7 @@ Upgrading from Rails 4.0 to Rails 4.1
|
|
|
32
272
|
Or, "whaaat my tests are failing!!!?"
|
|
33
273
|
|
|
34
274
|
Cross-site request forgery (CSRF) protection now covers GET requests with
|
|
35
|
-
JavaScript responses, too.
|
|
275
|
+
JavaScript responses, too. This prevents a third-party site from referencing
|
|
36
276
|
your JavaScript URL and attempting to run it to extract sensitive data.
|
|
37
277
|
|
|
38
278
|
This means that your functional and integration tests that use
|
|
@@ -47,7 +287,7 @@ will now trigger CSRF protection. Switch to
|
|
|
47
287
|
xhr :get, :index, format: :js
|
|
48
288
|
```
|
|
49
289
|
|
|
50
|
-
to explicitly test an XmlHttpRequest
|
|
290
|
+
to explicitly test an `XmlHttpRequest`.
|
|
51
291
|
|
|
52
292
|
If you really mean to load JavaScript from remote `<script>` tags, skip CSRF
|
|
53
293
|
protection on that action.
|
|
@@ -83,11 +323,11 @@ secrets, you need to:
|
|
|
83
323
|
```
|
|
84
324
|
|
|
85
325
|
2. Use your existing `secret_key_base` from the `secret_token.rb` initializer to
|
|
86
|
-
set the SECRET_KEY_BASE environment variable for whichever users
|
|
87
|
-
|
|
88
|
-
`secret_key_base` from the `secret_token.rb` initializer to `secrets.yml`
|
|
326
|
+
set the SECRET_KEY_BASE environment variable for whichever users running the
|
|
327
|
+
Rails application in production mode. Alternatively, you can simply copy the existing
|
|
328
|
+
`secret_key_base` from the `secret_token.rb` initializer to `secrets.yml`
|
|
89
329
|
under the `production` section, replacing '<%= ENV["SECRET_KEY_BASE"] %>'.
|
|
90
|
-
|
|
330
|
+
|
|
91
331
|
3. Remove the `secret_token.rb` initializer.
|
|
92
332
|
|
|
93
333
|
4. Use `rake secret` to generate new keys for the `development` and `test` sections.
|
|
@@ -98,7 +338,7 @@ secrets, you need to:
|
|
|
98
338
|
|
|
99
339
|
If your test helper contains a call to
|
|
100
340
|
`ActiveRecord::Migration.check_pending!` this can be removed. The check
|
|
101
|
-
is now done automatically when you `require 'test_help'`, although
|
|
341
|
+
is now done automatically when you `require 'rails/test_help'`, although
|
|
102
342
|
leaving this line in your helper is not harmful in any way.
|
|
103
343
|
|
|
104
344
|
### Cookies serializer
|
|
@@ -142,7 +382,7 @@ If you use the cookie session store, this would apply to the `session` and
|
|
|
142
382
|
|
|
143
383
|
Flash message keys are
|
|
144
384
|
[normalized to strings](https://github.com/rails/rails/commit/a668beffd64106a1e1fedb71cc25eaaa11baf0c1). They
|
|
145
|
-
can still be accessed using either symbols or strings.
|
|
385
|
+
can still be accessed using either symbols or strings. Looping through the flash
|
|
146
386
|
will always yield string keys:
|
|
147
387
|
|
|
148
388
|
```ruby
|
|
@@ -232,7 +472,7 @@ class ReadOnlyModel < ActiveRecord::Base
|
|
|
232
472
|
end
|
|
233
473
|
```
|
|
234
474
|
|
|
235
|
-
This
|
|
475
|
+
This behavior was never intentionally supported. Due to a change in the internals
|
|
236
476
|
of `ActiveSupport::Callbacks`, this is no longer allowed in Rails 4.1. Using a
|
|
237
477
|
`return` statement in an inline callback block causes a `LocalJumpError` to
|
|
238
478
|
be raised when the callback is executed.
|
|
@@ -287,8 +527,8 @@ ActiveRecord::FixtureSet.context_class.send :include, FixtureFileHelpers
|
|
|
287
527
|
|
|
288
528
|
### I18n enforcing available locales
|
|
289
529
|
|
|
290
|
-
Rails 4.1 now defaults the I18n option `enforce_available_locales` to `true
|
|
291
|
-
|
|
530
|
+
Rails 4.1 now defaults the I18n option `enforce_available_locales` to `true`. This
|
|
531
|
+
means that it will make sure that all locales passed to it must be declared in
|
|
292
532
|
the `available_locales` list.
|
|
293
533
|
|
|
294
534
|
To disable it (and allow I18n to accept *any* locale option) add the following
|
|
@@ -298,9 +538,10 @@ configuration to your application:
|
|
|
298
538
|
config.i18n.enforce_available_locales = false
|
|
299
539
|
```
|
|
300
540
|
|
|
301
|
-
Note that this option was added as a security measure, to ensure user input
|
|
302
|
-
|
|
303
|
-
to disable this option unless you have a strong reason for
|
|
541
|
+
Note that this option was added as a security measure, to ensure user input
|
|
542
|
+
cannot be used as locale information unless it is previously known. Therefore,
|
|
543
|
+
it's recommended not to disable this option unless you have a strong reason for
|
|
544
|
+
doing so.
|
|
304
545
|
|
|
305
546
|
### Mutator methods called on Relation
|
|
306
547
|
|
|
@@ -321,10 +562,10 @@ authors.compact!
|
|
|
321
562
|
|
|
322
563
|
### Changes on Default Scopes
|
|
323
564
|
|
|
324
|
-
Default scopes are no longer
|
|
565
|
+
Default scopes are no longer overridden by chained conditions.
|
|
325
566
|
|
|
326
567
|
In previous versions when you defined a `default_scope` in a model
|
|
327
|
-
it was
|
|
568
|
+
it was overridden by chained conditions in the same field. Now it
|
|
328
569
|
is merged like any other scope.
|
|
329
570
|
|
|
330
571
|
Before:
|
|
@@ -401,14 +642,14 @@ response body, you should be using `render :plain` as most browsers will escape
|
|
|
401
642
|
unsafe content in the response for you.
|
|
402
643
|
|
|
403
644
|
We will be deprecating the use of `render :text` in a future version. So please
|
|
404
|
-
start using the more precise `:plain
|
|
645
|
+
start using the more precise `:plain`, `:html`, and `:body` options instead.
|
|
405
646
|
Using `render :text` may pose a security risk, as the content is sent as
|
|
406
647
|
`text/html`.
|
|
407
648
|
|
|
408
649
|
### PostgreSQL json and hstore datatypes
|
|
409
650
|
|
|
410
651
|
Rails 4.1 will map `json` and `hstore` columns to a string-keyed Ruby `Hash`.
|
|
411
|
-
In earlier versions a `HashWithIndifferentAccess` was used. This means that
|
|
652
|
+
In earlier versions, a `HashWithIndifferentAccess` was used. This means that
|
|
412
653
|
symbol access is no longer supported. This is also the case for
|
|
413
654
|
`store_accessors` based on top of `json` or `hstore` columns. Make sure to use
|
|
414
655
|
string keys consistently.
|
|
@@ -514,7 +755,7 @@ def update
|
|
|
514
755
|
respond_to do |format|
|
|
515
756
|
format.json do
|
|
516
757
|
# perform a partial update
|
|
517
|
-
@
|
|
758
|
+
@article.update params[:article]
|
|
518
759
|
end
|
|
519
760
|
|
|
520
761
|
format.json_patch do
|
|
@@ -552,7 +793,7 @@ Rails 4.0 no longer supports loading plugins from `vendor/plugins`. You must rep
|
|
|
552
793
|
|
|
553
794
|
* 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`.
|
|
554
795
|
|
|
555
|
-
* The `delete` method in collection associations can now receive `
|
|
796
|
+
* The `delete` method in collection associations can now receive `Integer` 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.
|
|
556
797
|
|
|
557
798
|
* 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.
|
|
558
799
|
|
|
@@ -580,7 +821,7 @@ this gem such as `whitelist_attributes` or `mass_assignment_sanitizer` options.
|
|
|
580
821
|
* Rails 4.0 has deprecated `ActiveRecord::TestCase` in favor of `ActiveSupport::TestCase`.
|
|
581
822
|
|
|
582
823
|
* Rails 4.0 has deprecated the old-style hash based finder API. This means that
|
|
583
|
-
methods which previously accepted "finder options" no longer do.
|
|
824
|
+
methods which previously accepted "finder options" no longer do. For example, `Book.find(:all, conditions: { name: '1984' })` has been deprecated in favor of `Book.where(name: '1984')`
|
|
584
825
|
|
|
585
826
|
* All dynamic methods except for `find_by_...` and `find_by_...!` are deprecated.
|
|
586
827
|
Here's how you can handle the changes:
|
|
@@ -597,6 +838,20 @@ this gem such as `whitelist_attributes` or `mass_assignment_sanitizer` options.
|
|
|
597
838
|
|
|
598
839
|
* To re-enable the old finders, you can use the [activerecord-deprecated_finders gem](https://github.com/rails/activerecord-deprecated_finders).
|
|
599
840
|
|
|
841
|
+
* Rails 4.0 has changed to default join table for `has_and_belongs_to_many` relations to strip the common prefix off the second table name. Any existing `has_and_belongs_to_many` relationship between models with a common prefix must be specified with the `join_table` option. For example:
|
|
842
|
+
|
|
843
|
+
```ruby
|
|
844
|
+
CatalogCategory < ActiveRecord::Base
|
|
845
|
+
has_and_belongs_to_many :catalog_products, join_table: 'catalog_categories_catalog_products'
|
|
846
|
+
end
|
|
847
|
+
|
|
848
|
+
CatalogProduct < ActiveRecord::Base
|
|
849
|
+
has_and_belongs_to_many :catalog_categories, join_table: 'catalog_categories_catalog_products'
|
|
850
|
+
end
|
|
851
|
+
```
|
|
852
|
+
|
|
853
|
+
* Note that the the prefix takes scopes into account as well, so relations between `Catalog::Category` and `Catalog::Product` or `Catalog::Category` and `CatalogProduct` need to be updated similarly.
|
|
854
|
+
|
|
600
855
|
### Active Resource
|
|
601
856
|
|
|
602
857
|
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.
|
|
@@ -605,7 +860,7 @@ Rails 4.0 extracted Active Resource to its own gem. If you still need the featur
|
|
|
605
860
|
|
|
606
861
|
* 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`.
|
|
607
862
|
|
|
608
|
-
* 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
|
|
863
|
+
* 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 behavior. This means that you can comment or remove the following option in the `config/initializers/wrap_parameters.rb` file:
|
|
609
864
|
|
|
610
865
|
```ruby
|
|
611
866
|
# Disable root element in JSON by default.
|
|
@@ -640,6 +895,8 @@ Please read [Pull Request #9978](https://github.com/rails/rails/pull/9978) for d
|
|
|
640
895
|
|
|
641
896
|
* Rails 4.0 has removed the XML parameters parser. You will need to add the `actionpack-xml_parser` gem if you require this feature.
|
|
642
897
|
|
|
898
|
+
* Rails 4.0 changes the default `layout` lookup set using symbols or procs that return nil. To get the "no layout" behavior, return false instead of nil.
|
|
899
|
+
|
|
643
900
|
* Rails 4.0 changes the default memcached client from `memcache-client` to `dalli`. To upgrade, simply add `gem 'dalli'` to your `Gemfile`.
|
|
644
901
|
|
|
645
902
|
* 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.
|
|
@@ -731,7 +988,7 @@ The order in which helpers from more than one directory are loaded has changed i
|
|
|
731
988
|
|
|
732
989
|
### Active Record Observer and Action Controller Sweeper
|
|
733
990
|
|
|
734
|
-
|
|
991
|
+
`ActiveRecord::Observer` and `ActionController::Caching::Sweeper` have been extracted to the `rails-observers` gem. You will need to add the `rails-observers` gem if you require these features.
|
|
735
992
|
|
|
736
993
|
### sprockets-rails
|
|
737
994
|
|
|
@@ -749,17 +1006,18 @@ config.assets.js_compressor = :uglifier
|
|
|
749
1006
|
Upgrading from Rails 3.1 to Rails 3.2
|
|
750
1007
|
-------------------------------------
|
|
751
1008
|
|
|
752
|
-
If your application is currently on any version of Rails older than 3.1.x, you
|
|
1009
|
+
If your application is currently on any version of Rails older than 3.1.x, you
|
|
1010
|
+
should upgrade to Rails 3.1 before attempting an update to Rails 3.2.
|
|
753
1011
|
|
|
754
|
-
The following changes are meant for upgrading your application to
|
|
755
|
-
|
|
1012
|
+
The following changes are meant for upgrading your application to the latest
|
|
1013
|
+
3.2.x version of Rails.
|
|
756
1014
|
|
|
757
1015
|
### Gemfile
|
|
758
1016
|
|
|
759
1017
|
Make the following changes to your `Gemfile`.
|
|
760
1018
|
|
|
761
1019
|
```ruby
|
|
762
|
-
gem 'rails', '3.2.
|
|
1020
|
+
gem 'rails', '3.2.18'
|
|
763
1021
|
|
|
764
1022
|
group :assets do
|
|
765
1023
|
gem 'sass-rails', '~> 3.2.6'
|
|
@@ -884,7 +1142,7 @@ You can help test performance with these additions to your test environment:
|
|
|
884
1142
|
|
|
885
1143
|
```ruby
|
|
886
1144
|
# Configure static asset server for tests with Cache-Control for performance
|
|
887
|
-
config.
|
|
1145
|
+
config.serve_static_files = true
|
|
888
1146
|
config.static_cache_control = 'public, max-age=3600'
|
|
889
1147
|
```
|
|
890
1148
|
|
|
@@ -111,7 +111,9 @@ paintIt = (element, backgroundColor, textColor) ->
|
|
|
111
111
|
element.style.color = textColor
|
|
112
112
|
|
|
113
113
|
$ ->
|
|
114
|
-
$("a[data-background-color]").click ->
|
|
114
|
+
$("a[data-background-color]").click (e) ->
|
|
115
|
+
e.preventDefault()
|
|
116
|
+
|
|
115
117
|
backgroundColor = $(this).data("background-color")
|
|
116
118
|
textColor = $(this).data("text-color")
|
|
117
119
|
paintIt(this, backgroundColor, textColor)
|
|
@@ -156,7 +158,7 @@ is a helper that assists with writing forms. `form_for` takes a `:remote`
|
|
|
156
158
|
option. It works like this:
|
|
157
159
|
|
|
158
160
|
```erb
|
|
159
|
-
<%= form_for(@
|
|
161
|
+
<%= form_for(@article, remote: true) do |f| %>
|
|
160
162
|
...
|
|
161
163
|
<% end %>
|
|
162
164
|
```
|
|
@@ -164,7 +166,7 @@ option. It works like this:
|
|
|
164
166
|
This will generate the following HTML:
|
|
165
167
|
|
|
166
168
|
```html
|
|
167
|
-
<form accept-charset="UTF-8" action="/
|
|
169
|
+
<form accept-charset="UTF-8" action="/articles" class="new_article" data-remote="true" id="new_article" method="post">
|
|
168
170
|
...
|
|
169
171
|
</form>
|
|
170
172
|
```
|
|
@@ -178,10 +180,10 @@ bind to the `ajax:success` event. On failure, use `ajax:error`. Check it out:
|
|
|
178
180
|
|
|
179
181
|
```coffeescript
|
|
180
182
|
$(document).ready ->
|
|
181
|
-
$("#
|
|
182
|
-
$("#
|
|
183
|
+
$("#new_article").on("ajax:success", (e, data, status, xhr) ->
|
|
184
|
+
$("#new_article").append xhr.responseText
|
|
183
185
|
).on "ajax:error", (e, xhr, status, error) ->
|
|
184
|
-
$("#
|
|
186
|
+
$("#new_article").append "<p>ERROR</p>"
|
|
185
187
|
```
|
|
186
188
|
|
|
187
189
|
Obviously, you'll want to be a bit more sophisticated than that, but it's a
|
|
@@ -194,7 +196,7 @@ is very similar to `form_for`. It has a `:remote` option that you can use like
|
|
|
194
196
|
this:
|
|
195
197
|
|
|
196
198
|
```erb
|
|
197
|
-
<%= form_tag('/
|
|
199
|
+
<%= form_tag('/articles', remote: true) do %>
|
|
198
200
|
...
|
|
199
201
|
<% end %>
|
|
200
202
|
```
|
|
@@ -202,7 +204,7 @@ this:
|
|
|
202
204
|
This will generate the following HTML:
|
|
203
205
|
|
|
204
206
|
```html
|
|
205
|
-
<form accept-charset="UTF-8" action="/
|
|
207
|
+
<form accept-charset="UTF-8" action="/articles" data-remote="true" method="post">
|
|
206
208
|
...
|
|
207
209
|
</form>
|
|
208
210
|
```
|
|
@@ -217,21 +219,21 @@ is a helper that assists with generating links. It has a `:remote` option you
|
|
|
217
219
|
can use like this:
|
|
218
220
|
|
|
219
221
|
```erb
|
|
220
|
-
<%= link_to "
|
|
222
|
+
<%= link_to "an article", @article, remote: true %>
|
|
221
223
|
```
|
|
222
224
|
|
|
223
225
|
which generates
|
|
224
226
|
|
|
225
227
|
```html
|
|
226
|
-
<a href="/
|
|
228
|
+
<a href="/articles/1" data-remote="true">an article</a>
|
|
227
229
|
```
|
|
228
230
|
|
|
229
231
|
You can bind to the same Ajax events as `form_for`. Here's an example. Let's
|
|
230
|
-
assume that we have a list of
|
|
232
|
+
assume that we have a list of articles that can be deleted with just one
|
|
231
233
|
click. We would generate some HTML like this:
|
|
232
234
|
|
|
233
235
|
```erb
|
|
234
|
-
<%= link_to "Delete
|
|
236
|
+
<%= link_to "Delete article", @article, remote: true, method: :delete %>
|
|
235
237
|
```
|
|
236
238
|
|
|
237
239
|
and write some CoffeeScript like this:
|
|
@@ -239,7 +241,7 @@ and write some CoffeeScript like this:
|
|
|
239
241
|
```coffeescript
|
|
240
242
|
$ ->
|
|
241
243
|
$("a[data-remote]").on "ajax:success", (e, data, status, xhr) ->
|
|
242
|
-
alert "The
|
|
244
|
+
alert "The article was deleted."
|
|
243
245
|
```
|
|
244
246
|
|
|
245
247
|
### button_to
|
|
@@ -247,14 +249,14 @@ $ ->
|
|
|
247
249
|
[`button_to`](http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-button_to) is a helper that helps you create buttons. It has a `:remote` option that you can call like this:
|
|
248
250
|
|
|
249
251
|
```erb
|
|
250
|
-
<%= button_to "
|
|
252
|
+
<%= button_to "An article", @article, remote: true %>
|
|
251
253
|
```
|
|
252
254
|
|
|
253
255
|
this generates
|
|
254
256
|
|
|
255
257
|
```html
|
|
256
|
-
<form action="/
|
|
257
|
-
<div><input type="submit" value="
|
|
258
|
+
<form action="/articles/1" class="button_to" data-remote="true" method="post">
|
|
259
|
+
<div><input type="submit" value="An article"></div>
|
|
258
260
|
</form>
|
|
259
261
|
```
|
|
260
262
|
|
|
@@ -353,7 +355,7 @@ This gem uses Ajax to speed up page rendering in most applications.
|
|
|
353
355
|
|
|
354
356
|
Turbolinks attaches a click handler to all `<a>` on the page. If your browser
|
|
355
357
|
supports
|
|
356
|
-
[PushState](https://developer.mozilla.org/en-US/docs/DOM/Manipulating_the_browser_history#The_pushState
|
|
358
|
+
[PushState](https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history#The_pushState%28%29_method),
|
|
357
359
|
Turbolinks will make an Ajax request for the page, parse the response, and
|
|
358
360
|
replace the entire `<body>` of the page with the `<body>` of the response. It
|
|
359
361
|
will then use PushState to change the URL to the correct one, preserving
|
data/guides/w3c_validator.rb
CHANGED
|
@@ -60,6 +60,8 @@ module RailsGuides
|
|
|
60
60
|
def guides_to_validate
|
|
61
61
|
guides = Dir["./output/*.html"]
|
|
62
62
|
guides.delete("./output/layout.html")
|
|
63
|
+
guides.delete("./output/_license.html")
|
|
64
|
+
guides.delete("./output/_welcome.html")
|
|
63
65
|
ENV.key?('ONLY') ? select_only(guides) : guides
|
|
64
66
|
end
|
|
65
67
|
|