aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source
diff options
context:
space:
mode:
Diffstat (limited to 'guides/source')
-rw-r--r--guides/source/4_2_release_notes.md113
-rw-r--r--guides/source/_welcome.html.erb2
-rw-r--r--guides/source/action_mailer_basics.md14
-rw-r--r--guides/source/active_support_core_extensions.md20
-rw-r--r--guides/source/association_basics.md2
-rw-r--r--guides/source/contributing_to_ruby_on_rails.md2
-rw-r--r--guides/source/form_helpers.md10
-rw-r--r--guides/source/i18n.md2
-rw-r--r--guides/source/testing.md4
9 files changed, 85 insertions, 84 deletions
diff --git a/guides/source/4_2_release_notes.md b/guides/source/4_2_release_notes.md
index 330db52e34..1e9107a8c6 100644
--- a/guides/source/4_2_release_notes.md
+++ b/guides/source/4_2_release_notes.md
@@ -3,7 +3,8 @@ Ruby on Rails 4.2 Release Notes
Highlights in Rails 4.2:
-* Active Job, Action Mailer's `deliver_later`
+* Active Job
+* Asynchronous mails
* Adequate Record
* Web Console
* Foreign key support
@@ -29,7 +30,7 @@ Rails](upgrading_ruby_on_rails.html#upgrading-from-rails-4-1-to-rails-4-2).
Major Features
--------------
-### Active Job, Action Mailer's `deliver_later`
+### Active Job
Active Job is a new framework in Rails 4.2. It is a common interface on top of
queuing systems like [Resque](https://github.com/resque/resque), [Delayed
@@ -40,20 +41,34 @@ Jobs written with the Active Job API run on any of the supported queues thanks
to their respective adapters. Active Job comes pre-configured with an inline
runner that executes jobs right away.
-Building on top of Active Job, Action Mailer now comes with a `deliver_later`
-method that sends the email asynchronously via a job in a queue, so it doesn't
-block the controller or model.
+Jobs often need to take Active Record objects as arguments. Active Job passes
+object references as URIs (uniform resource identifiers) instead of marshaling
+the object itself. The new [Global ID](https://github.com/rails/globalid)
+library builds URIs and looks up the objects they reference. Passing Active
+Record objects as job arguments just works by using Global ID internally.
+
+For example, if `trashable` is an Active Record object, then this job runs
+just fine with no serialization involved:
-The new [Global ID](https://github.com/rails/globalid) library makes it easy
-to pass Active Record objects to jobs. The library stores a global URI that
-uniquely represents the model without serializing its state. This means you no
-longer have to manually pack and unpack your Active Records by passing ids.
-Just give the job the Active Record object, its global ID will be stored, and
-then the object transparently loaded for you from it.
+```ruby
+class TrashableCleanupJob < ActiveJob::Base
+ def perform(trashable, depth)
+ trashable.cleanup(depth)
+ end
+end
+```
See the [Active Job Basics](active_job_basics.html) guide for more
information.
+### Asynchronous Mails
+
+Building on top of Active Job, Action Mailer now comes with a `deliver_later`
+method that sends emails via the queue, so it doesn't block the controller or
+model if the queue is asynchronous (the default inline queue blocks).
+
+Sending emails right away is still possible with `deliver_now`.
+
### Adequate Record
Adequate Record is a set of performance improvements in Active Record that makes
@@ -64,9 +79,9 @@ on similar calls, skipping most of the query-generation work on subsequent
calls. For more details, please refer to [Aaron Patterson's blog
post](http://tenderlovemaking.com/2014/02/19/adequaterecord-pro-like-activerecord.html).
-Active Record will automatically take advantage of this feature on the
+Active Record will automatically take advantage of this feature on
supported operations without any user involvement or code changes. Here are
-some examples of the supported operations:
+some examples of supported operations:
```ruby
Post.find(1) # First call generates and cache the prepared statement
@@ -80,10 +95,10 @@ post.comments(true)
```
It's important to highlight that, as the examples above suggest, the prepared
-statements do not cache the values passed in the method calls, they rather
+statements do not cache the values passed in the method calls; rather, they
have placeholders for them.
-The caching is not used in the following scenarios:
+Caching is not used in the following scenarios:
- The model has a default scope
- The model uses single table inheritance
@@ -103,22 +118,15 @@ The caching is not used in the following scenarios:
### Web Console
-New applications generated from Rails 4.2 now come with the Web Console gem by
-default.
+New applications generated with Rails 4.2 now come with the [Web
+Console](https://github.com/rails/web-console) gem by default. Web Console adds
+an interactive Ruby console on every error page and provides a `console` view
+and controller helpers.
-Web Console is a set of debugging tools for your Rails application. It adds an
-interactive console on every error page and a `console` view and controller
-helper.
-
-The interactive console on the error pages lets you execute code where the
-exception originated. It's quite handy being able to introspect the state that
-led to the error.
-
-The `console` view helper launches an interactive console within the context of
-the view where it is invoked.
-
-The `console` controller helper spawns an interactive console within the
-context of the controller action it was invoked in.
+The interactive console on error pages lets you execute code in the context of
+the place where the exception originated. The `console` helper, if called
+anywhere in a view or controller, launches an interactive console with the final
+context, once rendering has completed.
### Foreign Key Support
@@ -158,11 +166,11 @@ The following changes may require immediate action upon upgrade.
### `render` with a String Argument
Previously, calling `render "foo/bar"` in a controller action was equivalent to
-`render file: "foo/bar"`. In Rails 4.2, this has been changed to mean `render template: "foo/bar"`
-instead. If you need to render a file, please change your code to use the
-explicit form (`render file: "foo/bar"`) instead.
+`render file: "foo/bar"`. In Rails 4.2, this has been changed to mean
+`render template: "foo/bar"` instead. If you need to render a file, please
+change your code to use the explicit form (`render file: "foo/bar"`) instead.
-### `respond_with` / class-level `respond_to`
+### `respond_with` / Class-Level `respond_to`
`respond_with` and the corresponding class-level `respond_to` have been moved
to the [responders](https://github.com/plataformatec/responders) gem. Add
@@ -201,8 +209,9 @@ end
Due to a [change in Rack](https://github.com/rack/rack/commit/28b014484a8ac0bbb388e7eaeeef159598ec64fc),
`rails server` now listens on `localhost` instead of `0.0.0.0` by default. This
-should have minimal impact on the standard development workflow as both http://127.0.0.1:3000
-and http://localhost:3000 will continue to work as before on your own machine.
+should have minimal impact on the standard development workflow as both
+http://127.0.0.1:3000 and http://localhost:3000 will continue to work as before
+on your own machine.
However, with this change you will no longer be able to access the Rails
server from a different machine, for example if your development environment
@@ -220,8 +229,8 @@ built upon [Loofah](https://github.com/flavorjones/loofah) and
[Nokogiri](https://github.com/sparklemotion/nokogiri). The new sanitizer is
more secure and its sanitization is more powerful and flexible.
-Due to the new algorithm, sanitized output changes for certain pathological
-inputs.
+Due to the new algorithm, the sanitized output may be different for certain
+pathological inputs.
If you have a particular need for the exact output of the old sanitizer, you
can add the [rails-deprecated_sanitizer](https://github.com/kaspth/rails-deprecated_sanitizer)
@@ -244,8 +253,13 @@ application is using any of these spellings, you will need to update them:
non-alphanumeric characters.
```
- a[href=/] => a[href="/"]
- a[href$=/] => a[href$="/"]
+ # before
+ a[href=/]
+ a[href$=/]
+
+ # now
+ a[href="/"]
+ a[href$="/"]
```
* DOMs built from HTML source containing invalid HTML with improperly
@@ -530,6 +544,17 @@ Please refer to the [Changelog][action-view] for detailed changes.
* Placeholder I18n follows the same convention as `label` I18n.
([Pull Request](https://github.com/rails/rails/pull/16438))
+* When calling the `process` helpers in an integration test the path needs to have
+ a leading slash. Previously you could omit it but that was a byproduct of the
+ implementation and not an intentional feature, e.g.:
+
+ ```ruby
+   test "list all posts" do
+     get "/posts"
+     assert_response :success 
+ end
+ ```
+
Action Mailer
-------------
@@ -649,8 +674,8 @@ Please refer to the [Changelog][active-record] for detailed changes.
current environment.
([Commit](https://github.com/rails/rails/commit/e2f232aba15937a4b9d14bd91e0392c6d55be58d))
-* Introduced `ActiveRecord::Base#validate!` that raises `ActiveRecord::RecordInvalid` if the
- record is invalid.
+* Introduced `ActiveRecord::Base#validate!` that raises
+ `ActiveRecord::RecordInvalid` if the record is invalid.
([Pull Request](https://github.com/rails/rails/pull/8639))
* Introduced `validate` as an alias for `valid?`.
@@ -690,8 +715,8 @@ Please refer to the [Changelog][active-record] for detailed changes.
`SELECT`s.
([Pull Request](https://github.com/rails/rails/pull/15866))
-* `ActiveRecord::Base#reflections` now returns a hash with string keys instead of symbol keys.
- ([Pull Request](https://github.com/rails/rails/pull/17718))
+* `ActiveRecord::Base#reflections` now returns a hash with string keys instead
+ of symbol keys. ([Pull Request](https://github.com/rails/rails/pull/17718))
* The `references` method in migrations now supports a `type` option for
specifying the type of the foreign key (e.g. `:uuid`).
diff --git a/guides/source/_welcome.html.erb b/guides/source/_welcome.html.erb
index f2315bfe22..614d69ecdd 100644
--- a/guides/source/_welcome.html.erb
+++ b/guides/source/_welcome.html.erb
@@ -15,5 +15,5 @@
</p>
<% end %>
<p>
- The guides for earlier releases: <a href="http://guides.rubyonrails.org/v4.1.6/">Rails 4.1.6</a>, <a href="http://guides.rubyonrails.org/v4.0.10/">Rails 4.0.10</a>, <a href="http://guides.rubyonrails.org/v3.2.19/">Rails 3.2.19</a> and <a href="http://guides.rubyonrails.org/v2.3.11/">Rails 2.3.11</a>.
+ The guides for earlier releases: <a href="http://guides.rubyonrails.org/v4.1.8/">Rails 4.1.8</a>, <a href="http://guides.rubyonrails.org/v4.0.12/">Rails 4.0.12</a>, <a href="http://guides.rubyonrails.org/v3.2.21/">Rails 3.2.21</a> and <a href="http://guides.rubyonrails.org/v2.3.11/">Rails 2.3.11</a>.
</p>
diff --git a/guides/source/action_mailer_basics.md b/guides/source/action_mailer_basics.md
index 2e8ab83241..ba7c16aa1d 100644
--- a/guides/source/action_mailer_basics.md
+++ b/guides/source/action_mailer_basics.md
@@ -470,16 +470,7 @@ By using the full URL, your links will now work in your emails.
#### generating URLs with `url_for`
-You need to pass the `only_path: false` option when using `url_for`. This will
-ensure that absolute URLs are generated because the `url_for` view helper will,
-by default, generate relative URLs when a `:host` option isn't explicitly
-provided.
-
-```erb
-<%= url_for(controller: 'welcome',
- action: 'greeting',
- only_path: false) %>
-```
+`url_for` generate full URL by default in templates.
If you did not configure the `:host` option globally make sure to pass it to
`url_for`.
@@ -491,9 +482,6 @@ If you did not configure the `:host` option globally make sure to pass it to
action: 'greeting') %>
```
-NOTE: When you explicitly pass the `:host` Rails will always generate absolute
-URLs, so there is no need to pass `only_path: false`.
-
#### generating URLs with named routes
Email clients have no web context and so paths have no base URL to form complete
diff --git a/guides/source/active_support_core_extensions.md b/guides/source/active_support_core_extensions.md
index 616b813817..faad34d021 100644
--- a/guides/source/active_support_core_extensions.md
+++ b/guides/source/active_support_core_extensions.md
@@ -1447,7 +1447,7 @@ Returns the substring of the string starting at position `position`:
"hello".from(0) # => "hello"
"hello".from(2) # => "llo"
"hello".from(-2) # => "lo"
-"hello".from(10) # => "" if < 1.9, nil in 1.9
+"hello".from(10) # => nil
```
NOTE: Defined in `active_support/core_ext/string/access.rb`.
@@ -1950,24 +1950,6 @@ as well as adding or subtracting their results from a Time object. For example:
(4.months + 5.years).from_now
```
-While these methods provide precise calculation when used as in the examples above, care
-should be taken to note that this is not true if the result of `months', `years', etc is
-converted before use:
-
-```ruby
-# equivalent to 30.days.to_i.from_now
-1.month.to_i.from_now
-
-# equivalent to 365.25.days.to_f.from_now
-1.year.to_f.from_now
-```
-
-In such cases, Ruby's core [Date](http://ruby-doc.org/stdlib/libdoc/date/rdoc/Date.html) and
-[Time](http://ruby-doc.org/stdlib/libdoc/time/rdoc/Time.html) should be used for precision
-date and time arithmetic.
-
-NOTE: Defined in `active_support/core_ext/numeric/time.rb`.
-
### Formatting
Enables the formatting of numbers in a variety of ways.
diff --git a/guides/source/association_basics.md b/guides/source/association_basics.md
index 61490ceb54..a12f5638e3 100644
--- a/guides/source/association_basics.md
+++ b/guides/source/association_basics.md
@@ -1532,8 +1532,6 @@ Controls what happens to the associated objects when their owner is destroyed:
* `:restrict_with_exception` causes an exception to be raised if there are any associated records
* `:restrict_with_error` causes an error to be added to the owner if there are any associated objects
-NOTE: This option is ignored when you use the `:through` option on the association.
-
##### `:foreign_key`
By convention, Rails assumes that the column used to hold the foreign key on the other model is the name of this model with the suffix `_id` added. The `:foreign_key` option lets you set the name of the foreign key directly:
diff --git a/guides/source/contributing_to_ruby_on_rails.md b/guides/source/contributing_to_ruby_on_rails.md
index 4eb360cc7a..8e7007d34a 100644
--- a/guides/source/contributing_to_ruby_on_rails.md
+++ b/guides/source/contributing_to_ruby_on_rails.md
@@ -205,7 +205,7 @@ Rails follows a simple set of coding style conventions:
* Use Ruby >= 1.9 syntax for hashes. Prefer `{ a: :b }` over `{ :a => :b }`.
* Prefer `&&`/`||` over `and`/`or`.
* Prefer class << self over self.method for class methods.
-* Use `MyClass.my_method(my_arg)` not `my_method( my_arg )` or `my_method my_arg`.
+* Use `my_method(my_arg)` not `my_method( my_arg )` or `my_method my_arg`.
* Use `a = b` and not `a=b`.
* Use assert_not methods instead of refute.
* Prefer `method { do_stuff }` instead of `method{do_stuff}` for single-line blocks.
diff --git a/guides/source/form_helpers.md b/guides/source/form_helpers.md
index cb45e38614..f3f7415b3c 100644
--- a/guides/source/form_helpers.md
+++ b/guides/source/form_helpers.md
@@ -96,7 +96,15 @@ form_tag({controller: "people", action: "search"}, method: "get", class: "nifty_
### Helpers for Generating Form Elements
-Rails provides a series of helpers for generating form elements such as checkboxes, text fields, and radio buttons. These basic helpers, with names ending in "_tag" (such as `text_field_tag` and `check_box_tag`), generate just a single `<input>` element. The first parameter to these is always the name of the input. When the form is submitted, the name will be passed along with the form data, and will make its way to the `params` hash in the controller with the value entered by the user for that field. For example, if the form contains `<%= text_field_tag(:query) %>`, then you would be able to get the value of this field in the controller with `params[:query]`.
+Rails provides a series of helpers for generating form elements such as
+checkboxes, text fields, and radio buttons. These basic helpers, with names
+ending in `_tag` (such as `text_field_tag` and `check_box_tag`), generate just a
+single `<input>` element. The first parameter to these is always the name of the
+input. When the form is submitted, the name will be passed along with the form
+data, and will make its way to the `params` hash in the controller with the
+value entered by the user for that field. For example, if the form contains `<%=
+text_field_tag(:query) %>`, then you would be able to get the value of this
+field in the controller with `params[:query]`.
When naming inputs, Rails uses certain conventions that make it possible to submit parameters with non-scalar values such as arrays or hashes, which will also be accessible in `params`. You can read more about them in [chapter 7 of this guide](#understanding-parameter-naming-conventions). For details on the precise usage of these helpers, please refer to the [API documentation](http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html).
diff --git a/guides/source/i18n.md b/guides/source/i18n.md
index f6cbc1823a..75b5275245 100644
--- a/guides/source/i18n.md
+++ b/guides/source/i18n.md
@@ -626,7 +626,7 @@ entry[count == 1 ? 0 : 1]
I.e. the translation denoted as `:one` is regarded as singular, the other is used as plural (including the count being zero).
-If the lookup for the key does not return a Hash suitable for pluralization, an `18n::InvalidPluralizationData` exception is raised.
+If the lookup for the key does not return a Hash suitable for pluralization, an `I18n::InvalidPluralizationData` exception is raised.
### Setting and Passing a Locale
diff --git a/guides/source/testing.md b/guides/source/testing.md
index b4c70dfa1d..d54f431d54 100644
--- a/guides/source/testing.md
+++ b/guides/source/testing.md
@@ -51,7 +51,7 @@ The `test_helper.rb` file holds the default configuration for your tests.
For good tests, you'll need to give some thought to setting up test data.
In Rails, you can handle this by defining and customizing fixtures.
-You can find comprehensive documentation in the [fixture api documentation](http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html).
+You can find comprehensive documentation in the [Fixtures API documentation](http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html).
#### What Are Fixtures?
@@ -100,7 +100,7 @@ Note: For associations to reference one another by name, you cannot specify the
attribute on the fixtures. Rails will auto assign a primary key to be consistent between
runs. If you manually specify an `id:` attribute, this behavior will not work. For more
information on this association behavior please read the
- [fixture api documentation](http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html).
+ [Fixtures API documentation](http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html).
#### ERB'in It Up