rails 4.2.2 → 4.2.11.3
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/guides/CHANGELOG.md +72 -2
- data/guides/Rakefile +16 -3
- data/guides/bug_report_templates/generic_gem.rb +15 -0
- data/guides/bug_report_templates/generic_master.rb +26 -0
- data/guides/rails_guides/levenshtein.rb +0 -2
- data/guides/source/4_2_release_notes.md +24 -0
- data/guides/source/_welcome.html.erb +5 -1
- data/guides/source/action_mailer_basics.md +4 -1
- data/guides/source/action_view_overview.md +2 -61
- data/guides/source/active_job_basics.md +27 -6
- data/guides/source/active_record_basics.md +6 -6
- data/guides/source/active_record_querying.md +1 -3
- data/guides/source/active_record_validations.md +3 -2
- data/guides/source/active_support_core_extensions.md +2 -50
- data/guides/source/active_support_instrumentation.md +0 -11
- data/guides/source/api_documentation_guidelines.md +1 -1
- data/guides/source/asset_pipeline.md +5 -40
- data/guides/source/association_basics.md +14 -4
- data/guides/source/autoloading_and_reloading_constants.md +2 -1
- data/guides/source/configuring.md +29 -4
- data/guides/source/contributing_to_ruby_on_rails.md +3 -3
- data/guides/source/engines.md +10 -10
- data/guides/source/getting_started.md +19 -24
- data/guides/source/i18n.md +1 -1
- data/guides/source/initialization.md +1 -1
- data/guides/source/layout.html.erb +4 -7
- data/guides/source/layouts_and_rendering.md +8 -9
- data/guides/source/rails_on_rack.md +0 -1
- data/guides/source/routing.md +15 -1
- data/guides/source/security.md +1 -1
- data/guides/source/testing.md +1 -1
- data/guides/source/upgrading_ruby_on_rails.md +17 -1
- data/guides/source/working_with_javascript_in_rails.md +1 -1
- metadata +21 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d4073c294efe444213b93605bd058bdfcfe7fd21df0673d411aaacb8444d6311
|
4
|
+
data.tar.gz: 6ced0776f690d103fd1ae235809fe9244f59538b6153c5f75247e76a35c9f600
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e399f8b1df884ceb451de70d9e0a821f1a0c4621eb7ee8af0e9fdc1a955661aab731e6b9a7b3928f09d2a86d492ec737f5c488709d2ba734cbb9a42a1ef5e829
|
7
|
+
data.tar.gz: d302ab1709953482477f8ca896e45e54d69c8dcc16edf1f49e09ce1c8b451d0a1725baf3d3c7a2b138b97ca0018813e2cf907db01768188a8a025e68c4679b16
|
data/guides/CHANGELOG.md
CHANGED
@@ -1,13 +1,83 @@
|
|
1
|
-
## Rails 4.2.
|
1
|
+
## Rails 4.2.11.3 (May 15, 2020) ##
|
2
|
+
|
3
|
+
* No changes.
|
4
|
+
|
5
|
+
|
6
|
+
## Rails 4.2.11.2 (May 15, 2020) ##
|
7
|
+
|
8
|
+
* No changes.
|
9
|
+
|
10
|
+
|
11
|
+
## Rails 4.2.11.1 (March 11, 2019) ##
|
12
|
+
|
13
|
+
* No changes.
|
14
|
+
|
15
|
+
|
16
|
+
## Rails 4.2.11 (November 27, 2018) ##
|
17
|
+
|
18
|
+
* No changes.
|
19
|
+
|
20
|
+
|
21
|
+
## Rails 4.2.10 (September 27, 2017) ##
|
22
|
+
|
23
|
+
* No changes.
|
24
|
+
|
25
|
+
|
26
|
+
## Rails 4.2.9 (June 26, 2017) ##
|
27
|
+
|
28
|
+
* No changes.
|
29
|
+
|
30
|
+
|
31
|
+
## Rails 4.2.8 (February 21, 2017) ##
|
32
|
+
|
33
|
+
* No changes.
|
34
|
+
|
35
|
+
|
36
|
+
## Rails 4.2.7 (July 12, 2016) ##
|
37
|
+
|
38
|
+
* No changes.
|
39
|
+
|
40
|
+
|
41
|
+
## Rails 4.2.6 (March 07, 2016) ##
|
42
|
+
|
43
|
+
* No changes.
|
44
|
+
|
45
|
+
|
46
|
+
## Rails 4.2.5.2 (February 26, 2016) ##
|
47
|
+
|
48
|
+
* No changes.
|
49
|
+
|
50
|
+
|
51
|
+
## Rails 4.2.5.1 (January 25, 2016) ##
|
52
|
+
|
53
|
+
* No changes.
|
54
|
+
|
55
|
+
|
56
|
+
## Rails 4.2.5 (November 12, 2015) ##
|
57
|
+
|
58
|
+
* No changes.
|
59
|
+
|
60
|
+
|
61
|
+
## Rails 4.2.4 (August 24, 2015) ##
|
62
|
+
|
63
|
+
* No Changes *
|
64
|
+
|
65
|
+
|
66
|
+
## Rails 4.2.3 (June 25, 2015) ##
|
2
67
|
|
3
68
|
* No Changes *
|
4
69
|
|
5
70
|
|
6
|
-
## Rails 4.2.
|
71
|
+
## Rails 4.2.2 (June 16, 2015) ##
|
7
72
|
|
8
73
|
* No Changes *
|
9
74
|
|
10
75
|
|
76
|
+
## Rails 4.2.1 (March 19, 2015) ##
|
77
|
+
|
78
|
+
* No changes.
|
79
|
+
|
80
|
+
|
11
81
|
## Rails 4.2.0 (December 20, 2014) ##
|
12
82
|
|
13
83
|
* New guide about constant autoloading and reloading.
|
data/guides/Rakefile
CHANGED
@@ -3,16 +3,29 @@ namespace :guides do
|
|
3
3
|
desc 'Generate guides (for authors), use ONLY=foo to process just "foo.md"'
|
4
4
|
task :generate => 'generate:html'
|
5
5
|
|
6
|
+
# Guides are written in UTF-8, but the environment may be configured for some
|
7
|
+
# other locale, these tasks are responsible for ensuring the default external
|
8
|
+
# encoding is UTF-8.
|
9
|
+
#
|
10
|
+
# Real use cases: Generation was reported to fail on a machine configured with
|
11
|
+
# GBK (Chinese). The docs server once got misconfigured somehow and had "C",
|
12
|
+
# which broke generation too.
|
13
|
+
task :encoding do
|
14
|
+
%w(LANG LANGUAGE LC_ALL).each do |env_var|
|
15
|
+
ENV[env_var] = "en_US.UTF-8"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
6
19
|
namespace :generate do
|
7
20
|
|
8
21
|
desc "Generate HTML guides"
|
9
|
-
task :html do
|
22
|
+
task :html => :encoding do
|
10
23
|
ENV["WARN_BROKEN_LINKS"] = "1" # authors can't disable this
|
11
24
|
ruby "rails_guides.rb"
|
12
25
|
end
|
13
26
|
|
14
27
|
desc "Generate .mobi file. The kindlegen executable must be in your PATH. You can get it for free from http://www.amazon.com/kindlepublishing"
|
15
|
-
task :kindle do
|
28
|
+
task :kindle => :encoding do
|
16
29
|
unless `kindlerb -v 2> /dev/null` =~ /kindlerb 0.1.1/
|
17
30
|
abort "Please `gem install kindlerb` and make sure you have `kindlegen` in your PATH"
|
18
31
|
end
|
@@ -26,7 +39,7 @@ namespace :guides do
|
|
26
39
|
|
27
40
|
# Validate guides -------------------------------------------------------------------------
|
28
41
|
desc 'Validate guides, use ONLY=foo to process just "foo.html"'
|
29
|
-
task :validate do
|
42
|
+
task :validate => :encoding do
|
30
43
|
ruby "w3c_validator.rb"
|
31
44
|
end
|
32
45
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Activate the gems you are reporting the issue against.
|
2
|
+
gem 'activesupport', '4.2.0'
|
3
|
+
require 'active_support'
|
4
|
+
require 'active_support/core_ext/object/blank'
|
5
|
+
require 'minitest/autorun'
|
6
|
+
|
7
|
+
# Ensure backward compatibility with Minitest 4
|
8
|
+
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
|
9
|
+
|
10
|
+
class BugTest < Minitest::Test
|
11
|
+
def test_stuff
|
12
|
+
assert "zomg".present?
|
13
|
+
refute "".present?
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
unless File.exist?('Gemfile')
|
2
|
+
File.write('Gemfile', <<-GEMFILE)
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
gem 'rails', github: 'rails/rails'
|
5
|
+
gem 'arel', github: 'rails/arel'
|
6
|
+
GEMFILE
|
7
|
+
|
8
|
+
system 'bundle'
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'bundler'
|
12
|
+
Bundler.setup(:default)
|
13
|
+
|
14
|
+
require 'active_support'
|
15
|
+
require 'active_support/core_ext/object/blank'
|
16
|
+
require 'minitest/autorun'
|
17
|
+
|
18
|
+
# Ensure backward compatibility with Minitest 4
|
19
|
+
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
|
20
|
+
|
21
|
+
class BugTest < Minitest::Test
|
22
|
+
def test_stuff
|
23
|
+
assert "zomg".present?
|
24
|
+
refute "".present?
|
25
|
+
end
|
26
|
+
end
|
@@ -300,6 +300,30 @@ application is using any of these spellings, you will need to update them:
|
|
300
300
|
assert_select('p', 'AT&T') # => false
|
301
301
|
```
|
302
302
|
|
303
|
+
Furthermore substitutions have changed syntax.
|
304
|
+
|
305
|
+
Now you have to use a `:match` CSS-like selector:
|
306
|
+
|
307
|
+
```ruby
|
308
|
+
assert_select ":match('id', ?)", 'comment_1'
|
309
|
+
```
|
310
|
+
|
311
|
+
Additionally Regexp substitutions look different when the assertion fails.
|
312
|
+
Notice how `/hello/` here:
|
313
|
+
|
314
|
+
```ruby
|
315
|
+
assert_select(":match('id', ?)", /hello/)
|
316
|
+
```
|
317
|
+
|
318
|
+
becomes `"(?-mix:hello)"`:
|
319
|
+
|
320
|
+
```
|
321
|
+
Expected at least 1 element matching "div:match('id', "(?-mix:hello)")", found 0..
|
322
|
+
Expected 0 to be >= 1.
|
323
|
+
```
|
324
|
+
|
325
|
+
See the [Rails Dom Testing](https://github.com/rails/rails-dom-testing/tree/8798b9349fb9540ad8cb9a0ce6cb88d1384a210b) documentation for more on `assert_select`.
|
326
|
+
|
303
327
|
|
304
328
|
Railties
|
305
329
|
--------
|
@@ -15,5 +15,9 @@
|
|
15
15
|
</p>
|
16
16
|
<% end %>
|
17
17
|
<p>
|
18
|
-
The guides for earlier releases:
|
18
|
+
The guides for earlier releases:
|
19
|
+
<a href="http://guides.rubyonrails.org/v4.1/">Rails 4.1</a>,
|
20
|
+
<a href="http://guides.rubyonrails.org/v4.0/">Rails 4.0</a>,
|
21
|
+
<a href="http://guides.rubyonrails.org/v3.2/">Rails 3.2</a>, and
|
22
|
+
<a href="http://guides.rubyonrails.org/v2.3/">Rails 2.3</a>.
|
19
23
|
</p>
|
@@ -507,6 +507,9 @@ url helper.
|
|
507
507
|
<%= user_url(@user, host: 'example.com') %>
|
508
508
|
```
|
509
509
|
|
510
|
+
NOTE: non-`GET` links require [jQuery UJS](https://github.com/rails/jquery-ujs)
|
511
|
+
and won't work in mailer templates. They will result in normal `GET` requests.
|
512
|
+
|
510
513
|
### Sending Multipart Emails
|
511
514
|
|
512
515
|
Action Mailer will automatically send multipart emails if you have different
|
@@ -670,7 +673,7 @@ files (environment.rb, production.rb, etc...)
|
|
670
673
|
| Configuration | Description |
|
671
674
|
|---------------|-------------|
|
672
675
|
|`logger`|Generates information on the mailing run if available. Can be set to `nil` for no logging. Compatible with both Ruby's own `Logger` and `Log4r` loggers.|
|
673
|
-
|`smtp_settings`|Allows detailed configuration for `:smtp` delivery method:<ul><li>`:address` - Allows you to use a remote mail server. Just change it from its default `"localhost"` setting.</li><li>`:port` - On the off chance that your mail server doesn't run on port 25, you can change it.</li><li>`:domain` - If you need to specify a HELO domain, you can do it here.</li><li>`:user_name` - If your mail server requires authentication, set the username in this setting.</li><li>`:password` - If your mail server requires authentication, set the password in this setting.</li><li>`:authentication` - If your mail server requires authentication, you need to specify the authentication type here. This is a symbol and one of `:plain
|
676
|
+
|`smtp_settings`|Allows detailed configuration for `:smtp` delivery method:<ul><li>`:address` - Allows you to use a remote mail server. Just change it from its default `"localhost"` setting.</li><li>`:port` - On the off chance that your mail server doesn't run on port 25, you can change it.</li><li>`:domain` - If you need to specify a HELO domain, you can do it here.</li><li>`:user_name` - If your mail server requires authentication, set the username in this setting.</li><li>`:password` - If your mail server requires authentication, set the password in this setting.</li><li>`:authentication` - If your mail server requires authentication, you need to specify the authentication type here. This is a symbol and one of `:plain` (will send the password in the clear), `:login` (will send password Base64 encoded) or `:cram_md5` (combines a Challenge/Response mechanism to exchange information and a cryptographic Message Digest 5 algorithm to hash important information)</li><li>`:enable_starttls_auto` - Detects if STARTTLS is enabled in your SMTP server and starts to use it. Defaults to `true`.</li><li>`:openssl_verify_mode` - When using TLS, you can set how OpenSSL checks the certificate. This is really useful if you need to validate a self-signed and/or a wildcard certificate. You can use the name of an OpenSSL verify constant ('none', 'peer', 'client_once', 'fail_if_no_peer_cert') or directly the constant (`OpenSSL::SSL::VERIFY_NONE`, `OpenSSL::SSL::VERIFY_PEER`, ...).</li></ul>|
|
674
677
|
|`sendmail_settings`|Allows you to override options for the `:sendmail` delivery method.<ul><li>`:location` - The location of the sendmail executable. Defaults to `/usr/sbin/sendmail`.</li><li>`:arguments` - The command line arguments to be passed to sendmail. Defaults to `-i -t`.</li></ul>|
|
675
678
|
|`raise_delivery_errors`|Whether or not errors should be raised if the email fails to be delivered. This only works if the external email server is configured for immediate delivery.|
|
676
679
|
|`delivery_method`|Defines a delivery method. Possible values are:<ul><li>`:smtp` (default), can be configured by using `config.action_mailer.smtp_settings`.</li><li>`:sendmail`, can be configured by using `config.action_mailer.sendmail_settings`.</li><li>`:file`: save emails to files; can be configured by using `config.action_mailer.file_settings`.</li><li>`:test`: save emails to `ActionMailer::Base.deliveries` array.</li></ul>See [API docs](http://api.rubyonrails.org/classes/ActionMailer/Base.html) for more info.|
|
@@ -435,39 +435,13 @@ config.action_controller.asset_host = "assets.example.com"
|
|
435
435
|
image_tag("rails.png") # => <img src="http://assets.example.com/images/rails.png" alt="Rails" />
|
436
436
|
```
|
437
437
|
|
438
|
-
#### register_javascript_expansion
|
439
|
-
|
440
|
-
Register one or more JavaScript files to be included when symbol is passed to javascript_include_tag. This method is typically intended to be called from plugin initialization to register JavaScript files that the plugin installed in `vendor/assets/javascripts`.
|
441
|
-
|
442
|
-
```ruby
|
443
|
-
ActionView::Helpers::AssetTagHelper.register_javascript_expansion monkey: ["head", "body", "tail"]
|
444
|
-
|
445
|
-
javascript_include_tag :monkey # =>
|
446
|
-
<script src="/assets/head.js"></script>
|
447
|
-
<script src="/assets/body.js"></script>
|
448
|
-
<script src="/assets/tail.js"></script>
|
449
|
-
```
|
450
|
-
|
451
|
-
#### register_stylesheet_expansion
|
452
|
-
|
453
|
-
Register one or more stylesheet files to be included when symbol is passed to `stylesheet_link_tag`. This method is typically intended to be called from plugin initialization to register stylesheet files that the plugin installed in `vendor/assets/stylesheets`.
|
454
|
-
|
455
|
-
```ruby
|
456
|
-
ActionView::Helpers::AssetTagHelper.register_stylesheet_expansion monkey: ["head", "body", "tail"]
|
457
|
-
|
458
|
-
stylesheet_link_tag :monkey # =>
|
459
|
-
<link href="/assets/head.css" media="screen" rel="stylesheet" />
|
460
|
-
<link href="/assets/body.css" media="screen" rel="stylesheet" />
|
461
|
-
<link href="/assets/tail.css" media="screen" rel="stylesheet" />
|
462
|
-
```
|
463
|
-
|
464
438
|
#### auto_discovery_link_tag
|
465
439
|
|
466
440
|
Returns a link tag that browsers and feed readers can use to auto-detect an RSS or Atom feed.
|
467
441
|
|
468
442
|
```ruby
|
469
|
-
auto_discovery_link_tag(:rss, "http://www.example.com/feed.rss", {title: "RSS Feed"}) # =>
|
470
|
-
<link rel="alternate" type="application/rss+xml" title="RSS Feed" href="http://www.example.com/feed" />
|
443
|
+
auto_discovery_link_tag(:rss, "http://www.example.com/feed.rss", { title: "RSS Feed" }) # =>
|
444
|
+
<link rel="alternate" type="application/rss+xml" title="RSS Feed" href="http://www.example.com/feed.rss" />
|
471
445
|
```
|
472
446
|
|
473
447
|
#### image_path
|
@@ -1136,14 +1110,6 @@ If `@article.author_ids` is [1], this would return:
|
|
1136
1110
|
<input name="article[author_ids][]" type="hidden" value="" />
|
1137
1111
|
```
|
1138
1112
|
|
1139
|
-
#### country_options_for_select
|
1140
|
-
|
1141
|
-
Returns a string of option tags for pretty much any country in the world.
|
1142
|
-
|
1143
|
-
#### country_select
|
1144
|
-
|
1145
|
-
Returns select and option tags for the given object and method, using country_options_for_select to generate the list of option tags.
|
1146
|
-
|
1147
1113
|
#### option_groups_from_collection_for_select
|
1148
1114
|
|
1149
1115
|
Returns a string of `option` tags, like `options_from_collection_for_select`, but groups them by `optgroup` tags based on the object relationships of the arguments.
|
@@ -1420,22 +1386,6 @@ date_field_tag "dob"
|
|
1420
1386
|
|
1421
1387
|
Provides functionality for working with JavaScript in your views.
|
1422
1388
|
|
1423
|
-
#### button_to_function
|
1424
|
-
|
1425
|
-
Returns a button that'll trigger a JavaScript function using the onclick handler. Examples:
|
1426
|
-
|
1427
|
-
```ruby
|
1428
|
-
button_to_function "Greeting", "alert('Hello world!')"
|
1429
|
-
button_to_function "Delete", "if (confirm('Really?')) do_delete()"
|
1430
|
-
button_to_function "Details" do |page|
|
1431
|
-
page[:details].visual_effect :toggle_slide
|
1432
|
-
end
|
1433
|
-
```
|
1434
|
-
|
1435
|
-
#### define_javascript_functions
|
1436
|
-
|
1437
|
-
Includes the Action Pack JavaScript libraries inside a single `script` tag.
|
1438
|
-
|
1439
1389
|
#### escape_javascript
|
1440
1390
|
|
1441
1391
|
Escape carrier returns and single and double quotes for JavaScript segments.
|
@@ -1456,15 +1406,6 @@ alert('All is good')
|
|
1456
1406
|
</script>
|
1457
1407
|
```
|
1458
1408
|
|
1459
|
-
#### link_to_function
|
1460
|
-
|
1461
|
-
Returns a link that will trigger a JavaScript function using the onclick handler and return false after the fact.
|
1462
|
-
|
1463
|
-
```ruby
|
1464
|
-
link_to_function "Greeting", "alert('Hello world!')"
|
1465
|
-
# => <a onclick="alert('Hello world!'); return false;" href="#">Greeting</a>
|
1466
|
-
```
|
1467
|
-
|
1468
1409
|
### NumberHelper
|
1469
1410
|
|
1470
1411
|
Provides methods for converting numbers into formatted strings. Methods are provided for phone numbers, currency, percentage, precision, positional notation, and file size.
|
@@ -65,33 +65,41 @@ Here's what a job looks like:
|
|
65
65
|
class GuestsCleanupJob < ActiveJob::Base
|
66
66
|
queue_as :default
|
67
67
|
|
68
|
-
def perform(*
|
68
|
+
def perform(*guests)
|
69
69
|
# Do something later
|
70
70
|
end
|
71
71
|
end
|
72
72
|
```
|
73
73
|
|
74
|
+
Note that you can define `perform` with as many arguments as you want.
|
75
|
+
|
74
76
|
### Enqueue the Job
|
75
77
|
|
76
78
|
Enqueue a job like so:
|
77
79
|
|
78
80
|
```ruby
|
79
|
-
# Enqueue a job to be performed as soon the
|
80
|
-
|
81
|
+
# Enqueue a job to be performed as soon the queuing system is
|
82
|
+
# free.
|
83
|
+
GuestsCleanupJob.perform_later guest
|
81
84
|
```
|
82
85
|
|
83
86
|
```ruby
|
84
87
|
# Enqueue a job to be performed tomorrow at noon.
|
85
|
-
|
88
|
+
GuestsCleanupJob.set(wait_until: Date.tomorrow.noon).perform_later(guest)
|
86
89
|
```
|
87
90
|
|
88
91
|
```ruby
|
89
92
|
# Enqueue a job to be performed 1 week from now.
|
90
|
-
|
93
|
+
GuestsCleanupJob.set(wait: 1.week).perform_later(guest)
|
91
94
|
```
|
92
95
|
|
93
|
-
|
96
|
+
```ruby
|
97
|
+
# `perform_now` and `perform_later` will call `perform` under the hood so
|
98
|
+
# you can pass as many arguments as defined in the latter.
|
99
|
+
GuestsCleanupJob.perform_later(guest1, guest2, filter: 'some_filter')
|
100
|
+
```
|
94
101
|
|
102
|
+
That's it!
|
95
103
|
|
96
104
|
Job Execution
|
97
105
|
-------------
|
@@ -266,6 +274,19 @@ UserMailer.welcome(@user).deliver_later
|
|
266
274
|
```
|
267
275
|
|
268
276
|
|
277
|
+
Internationalization
|
278
|
+
--------------------
|
279
|
+
|
280
|
+
Each job uses the `I18n.locale` set when the job was created. Useful if you send
|
281
|
+
emails asynchronously:
|
282
|
+
|
283
|
+
```ruby
|
284
|
+
I18n.locale = :eo
|
285
|
+
|
286
|
+
UserMailer.welcome(@user).deliver_later # Email will be localized to Esparanto.
|
287
|
+
```
|
288
|
+
|
289
|
+
|
269
290
|
GlobalID
|
270
291
|
--------
|
271
292
|
|
@@ -171,18 +171,18 @@ name that should be used:
|
|
171
171
|
|
172
172
|
```ruby
|
173
173
|
class Product < ActiveRecord::Base
|
174
|
-
self.table_name = "
|
174
|
+
self.table_name = "my_products"
|
175
175
|
end
|
176
176
|
```
|
177
177
|
|
178
178
|
If you do so, you will have to define manually the class name that is hosting
|
179
|
-
the fixtures (
|
179
|
+
the fixtures (my_products.yml) using the `set_fixture_class` method in your test
|
180
180
|
definition:
|
181
181
|
|
182
182
|
```ruby
|
183
|
-
class
|
184
|
-
set_fixture_class
|
185
|
-
fixtures :
|
183
|
+
class ProductTest < ActiveSupport::TestCase
|
184
|
+
set_fixture_class my_products: Product
|
185
|
+
fixtures :my_products
|
186
186
|
...
|
187
187
|
end
|
188
188
|
```
|
@@ -258,7 +258,7 @@ david = User.find_by(name: 'David')
|
|
258
258
|
|
259
259
|
```ruby
|
260
260
|
# find all users named David who are Code Artists and sort by created_at in reverse chronological order
|
261
|
-
users = User.where(name: 'David', occupation: 'Code Artist').order(
|
261
|
+
users = User.where(name: 'David', occupation: 'Code Artist').order(created_at: :desc)
|
262
262
|
```
|
263
263
|
|
264
264
|
You can learn more about querying an Active Record model in the [Active Record
|
@@ -332,8 +332,6 @@ User.find_each(start: 2000, batch_size: 5000) do |user|
|
|
332
332
|
end
|
333
333
|
```
|
334
334
|
|
335
|
-
Another example would be if you wanted multiple workers handling the same processing queue. You could have each worker handle 10000 records by setting the appropriate `:start` option on each worker.
|
336
|
-
|
337
335
|
#### `find_in_batches`
|
338
336
|
|
339
337
|
The `find_in_batches` method is similar to `find_each`, since both retrieve batches of records. The difference is that `find_in_batches` yields _batches_ to the block as an array of models, instead of individually. The following example will yield to the supplied block an array of up to 1000 invoices at a time, with the final block containing any remaining invoices:
|
@@ -876,7 +874,7 @@ For example:
|
|
876
874
|
Item.transaction do
|
877
875
|
i = Item.lock.first
|
878
876
|
i.name = 'Jones'
|
879
|
-
i.save
|
877
|
+
i.save!
|
880
878
|
end
|
881
879
|
```
|
882
880
|
|
@@ -944,8 +944,9 @@ own custom validators.
|
|
944
944
|
|
945
945
|
You can also create methods that verify the state of your models and add
|
946
946
|
messages to the `errors` collection when they are invalid. You must then
|
947
|
-
register these methods by using the `validate`
|
948
|
-
|
947
|
+
register these methods by using the `validate`
|
948
|
+
([API](http://api.rubyonrails.org/classes/ActiveModel/Validations/ClassMethods.html#method-i-validate))
|
949
|
+
class method, passing in the symbols for the validation methods' names.
|
949
950
|
|
950
951
|
You can pass more than one symbol for each class method and the respective
|
951
952
|
validations will be run in the same order as they were registered.
|
@@ -1760,7 +1760,7 @@ NOTE: Defined in `active_support/core_ext/string/inflections.rb`.
|
|
1760
1760
|
The method `constantize` resolves the constant reference expression in its receiver:
|
1761
1761
|
|
1762
1762
|
```ruby
|
1763
|
-
"
|
1763
|
+
"Integer".constantize # => Integer
|
1764
1764
|
|
1765
1765
|
module M
|
1766
1766
|
X = 1
|
@@ -2612,8 +2612,7 @@ To do so, the method loops over the pairs and builds nodes that depend on the _v
|
|
2612
2612
|
```ruby
|
2613
2613
|
XML_TYPE_NAMES = {
|
2614
2614
|
"Symbol" => "symbol",
|
2615
|
-
"
|
2616
|
-
"Bignum" => "integer",
|
2615
|
+
"Integer" => "integer",
|
2617
2616
|
"BigDecimal" => "decimal",
|
2618
2617
|
"Float" => "float",
|
2619
2618
|
"TrueClass" => "boolean",
|
@@ -3043,53 +3042,6 @@ The method `Range#overlaps?` says whether any two given ranges have non-void int
|
|
3043
3042
|
|
3044
3043
|
NOTE: Defined in `active_support/core_ext/range/overlaps.rb`.
|
3045
3044
|
|
3046
|
-
Extensions to `Proc`
|
3047
|
-
--------------------
|
3048
|
-
|
3049
|
-
### `bind`
|
3050
|
-
|
3051
|
-
As you surely know Ruby has an `UnboundMethod` class whose instances are methods that belong to the limbo of methods without a self. The method `Module#instance_method` returns an unbound method for example:
|
3052
|
-
|
3053
|
-
```ruby
|
3054
|
-
Hash.instance_method(:delete) # => #<UnboundMethod: Hash#delete>
|
3055
|
-
```
|
3056
|
-
|
3057
|
-
An unbound method is not callable as is, you need to bind it first to an object with `bind`:
|
3058
|
-
|
3059
|
-
```ruby
|
3060
|
-
clear = Hash.instance_method(:clear)
|
3061
|
-
clear.bind({a: 1}).call # => {}
|
3062
|
-
```
|
3063
|
-
|
3064
|
-
Active Support defines `Proc#bind` with an analogous purpose:
|
3065
|
-
|
3066
|
-
```ruby
|
3067
|
-
Proc.new { size }.bind([]).call # => 0
|
3068
|
-
```
|
3069
|
-
|
3070
|
-
As you see that's callable and bound to the argument, the return value is indeed a `Method`.
|
3071
|
-
|
3072
|
-
NOTE: To do so `Proc#bind` actually creates a method under the hood. If you ever see a method with a weird name like `__bind_1256598120_237302` in a stack trace you know now where it comes from.
|
3073
|
-
|
3074
|
-
Action Pack uses this trick in `rescue_from` for example, which accepts the name of a method and also a proc as callbacks for a given rescued exception. It has to call them in either case, so a bound method is returned by `handler_for_rescue`, thus simplifying the code in the caller:
|
3075
|
-
|
3076
|
-
```ruby
|
3077
|
-
def handler_for_rescue(exception)
|
3078
|
-
_, rescuer = Array(rescue_handlers).reverse.detect do |klass_name, handler|
|
3079
|
-
...
|
3080
|
-
end
|
3081
|
-
|
3082
|
-
case rescuer
|
3083
|
-
when Symbol
|
3084
|
-
method(rescuer)
|
3085
|
-
when Proc
|
3086
|
-
rescuer.bind(self)
|
3087
|
-
end
|
3088
|
-
end
|
3089
|
-
```
|
3090
|
-
|
3091
|
-
NOTE: Defined in `active_support/core_ext/proc.rb`.
|
3092
|
-
|
3093
3045
|
Extensions to `Date`
|
3094
3046
|
--------------------
|
3095
3047
|
|
@@ -305,17 +305,6 @@ Action Mailer
|
|
305
305
|
}
|
306
306
|
```
|
307
307
|
|
308
|
-
ActiveResource
|
309
|
-
--------------
|
310
|
-
|
311
|
-
### request.active_resource
|
312
|
-
|
313
|
-
| Key | Value |
|
314
|
-
| -------------- | -------------------- |
|
315
|
-
| `:method` | HTTP method |
|
316
|
-
| `:request_uri` | Complete URI |
|
317
|
-
| `:result` | HTTP response object |
|
318
|
-
|
319
308
|
Active Support
|
320
309
|
--------------
|
321
310
|
|
@@ -111,7 +111,7 @@ On the other hand, big chunks of structured documentation may have a separate "E
|
|
111
111
|
The results of expressions follow them and are introduced by "# => ", vertically aligned:
|
112
112
|
|
113
113
|
```ruby
|
114
|
-
# For checking if
|
114
|
+
# For checking if an integer is even or odd.
|
115
115
|
#
|
116
116
|
# 1.even? # => false
|
117
117
|
# 1.odd? # => true
|
@@ -434,11 +434,11 @@ Sprockets uses manifest files to determine which assets to include and serve.
|
|
434
434
|
These manifest files contain _directives_ - instructions that tell Sprockets
|
435
435
|
which files to require in order to build a single CSS or JavaScript file. With
|
436
436
|
these directives, Sprockets loads the files specified, processes them if
|
437
|
-
necessary, concatenates them into one single file and then compresses them
|
438
|
-
`Rails.application.config.assets.
|
439
|
-
than many, the load time of pages can be greatly reduced because
|
440
|
-
makes fewer requests. Compression also reduces file size, enabling
|
441
|
-
browser to download them faster.
|
437
|
+
necessary, concatenates them into one single file and then compresses them
|
438
|
+
(based on value of `Rails.application.config.assets.js_compressor`). By serving
|
439
|
+
one file rather than many, the load time of pages can be greatly reduced because
|
440
|
+
the browser makes fewer requests. Compression also reduces file size, enabling
|
441
|
+
the browser to download them faster.
|
442
442
|
|
443
443
|
|
444
444
|
For example, a new Rails 4 application includes a default
|
@@ -789,41 +789,6 @@ location ~ ^/assets/ {
|
|
789
789
|
}
|
790
790
|
```
|
791
791
|
|
792
|
-
#### GZip Compression
|
793
|
-
|
794
|
-
When files are precompiled, Sprockets also creates a
|
795
|
-
[gzipped](http://en.wikipedia.org/wiki/Gzip) (.gz) version of your assets. Web
|
796
|
-
servers are typically configured to use a moderate compression ratio as a
|
797
|
-
compromise, but since precompilation happens once, Sprockets uses the maximum
|
798
|
-
compression ratio, thus reducing the size of the data transfer to the minimum.
|
799
|
-
On the other hand, web servers can be configured to serve compressed content
|
800
|
-
directly from disk, rather than deflating non-compressed files themselves.
|
801
|
-
|
802
|
-
NGINX is able to do this automatically enabling `gzip_static`:
|
803
|
-
|
804
|
-
```nginx
|
805
|
-
location ~ ^/(assets)/ {
|
806
|
-
root /path/to/public;
|
807
|
-
gzip_static on; # to serve pre-gzipped version
|
808
|
-
expires max;
|
809
|
-
add_header Cache-Control public;
|
810
|
-
}
|
811
|
-
```
|
812
|
-
|
813
|
-
This directive is available if the core module that provides this feature was
|
814
|
-
compiled with the web server. Ubuntu/Debian packages, even `nginx-light`, have
|
815
|
-
the module compiled. Otherwise, you may need to perform a manual compilation:
|
816
|
-
|
817
|
-
```bash
|
818
|
-
./configure --with-http_gzip_static_module
|
819
|
-
```
|
820
|
-
|
821
|
-
If you're compiling NGINX with Phusion Passenger you'll need to pass that option
|
822
|
-
when prompted.
|
823
|
-
|
824
|
-
A robust configuration for Apache is possible but tricky; please Google around.
|
825
|
-
(Or help update this Guide if you have a good configuration example for Apache.)
|
826
|
-
|
827
792
|
### Local Precompilation
|
828
793
|
|
829
794
|
There are several reasons why you might want to precompile your assets locally.
|