diff options
Diffstat (limited to 'guides/source')
-rw-r--r-- | guides/source/4_2_release_notes.md | 95 | ||||
-rw-r--r-- | guides/source/action_mailer_basics.md | 14 | ||||
-rw-r--r-- | guides/source/active_support_core_extensions.md | 20 | ||||
-rw-r--r-- | guides/source/contributing_to_ruby_on_rails.md | 2 | ||||
-rw-r--r-- | guides/source/i18n.md | 2 | ||||
-rw-r--r-- | guides/source/testing.md | 4 |
6 files changed, 63 insertions, 74 deletions
diff --git a/guides/source/4_2_release_notes.md b/guides/source/4_2_release_notes.md index c3803aa856..1e9107a8c6 100644 --- a/guides/source/4_2_release_notes.md +++ b/guides/source/4_2_release_notes.md @@ -4,7 +4,7 @@ Ruby on Rails 4.2 Release Notes Highlights in Rails 4.2: * Active Job -* Asynchronous Mails +* Asynchronous mails * Adequate Record * Web Console * Foreign key support @@ -41,13 +41,22 @@ 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. -Jobs often need to take Active Record objects as arguments, but we can't pass -fully-marshaled Ruby objects through many queueing systems. Active Job passes +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:" Active Job passes a reference to -the object, then looks up the object from its reference. +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: + +```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. @@ -70,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 @@ -86,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 @@ -109,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. - -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. +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. -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 @@ -164,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 @@ -207,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 @@ -226,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) @@ -250,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 @@ -536,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 ------------- @@ -655,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?`. @@ -696,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/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/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/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 |