aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source
diff options
context:
space:
mode:
Diffstat (limited to 'guides/source')
-rw-r--r--guides/source/4_1_release_notes.md2
-rw-r--r--guides/source/4_2_release_notes.md41
-rw-r--r--guides/source/_welcome.html.erb4
-rw-r--r--guides/source/active_model_basics.md23
-rw-r--r--guides/source/active_record_validations.md2
-rw-r--r--guides/source/active_support_core_extensions.md4
-rw-r--r--guides/source/command_line.md16
-rw-r--r--guides/source/debugging_rails_applications.md12
-rw-r--r--guides/source/engines.md18
-rw-r--r--guides/source/generators.md4
-rw-r--r--guides/source/getting_started.md2
-rw-r--r--guides/source/i18n.md4
-rw-r--r--guides/source/upgrading_ruby_on_rails.md14
13 files changed, 95 insertions, 51 deletions
diff --git a/guides/source/4_1_release_notes.md b/guides/source/4_1_release_notes.md
index 822943d81e..5f4bdaaa8f 100644
--- a/guides/source/4_1_release_notes.md
+++ b/guides/source/4_1_release_notes.md
@@ -157,7 +157,7 @@ By default, these preview classes live in `test/mailers/previews`.
This can be configured using the `preview_path` option.
See its
-[documentation](http://api.rubyonrails.org/v4.1.0/classes/ActionMailer/Base.html)
+[documentation](http://api.rubyonrails.org/v4.1.0/classes/ActionMailer/Base.html#class-ActionMailer::Base-label-Previewing+emails)
for a detailed write up.
### Active Record enums
diff --git a/guides/source/4_2_release_notes.md b/guides/source/4_2_release_notes.md
index 1bb912b678..f4c2eb8945 100644
--- a/guides/source/4_2_release_notes.md
+++ b/guides/source/4_2_release_notes.md
@@ -55,9 +55,7 @@ for a full description.
Railties
--------
-Please refer to the
-[Changelog](https://github.com/rails/rails/blob/4-2-stable/railties/CHANGELOG.md)
-for detailed changes.
+Please refer to the [Changelog][railties] for detailed changes.
### Removals
@@ -82,9 +80,7 @@ for detailed changes.
Action Pack
-----------
-Please refer to the
-[Changelog](https://github.com/rails/rails/blob/4-2-stable/actionpack/CHANGELOG.md)
-for detailed changes.
+Please refer to the [Changelog][action-pack] for detailed changes.
### Deprecations
@@ -143,9 +139,7 @@ for detailed changes.
Action View
-------------
-Please refer to the
-[Changelog](https://github.com/rails/rails/blob/4-2-stable/actionview/CHANGELOG.md)
-for detailed changes.
+Please refer to the [Changelog][action-view] for detailed changes.
### Deprecations
@@ -164,9 +158,7 @@ for detailed changes.
Action Mailer
-------------
-Please refer to the
-[Changelog](https://github.com/rails/rails/blob/4-2-stable/actionmailer/CHANGELOG.md)
-for detailed changes.
+Please refer to the [Changelog][action-mailer] for detailed changes.
### Notable changes
@@ -262,12 +254,14 @@ for detailed changes.
* Added support for user-created range types in PostgreSQL adapter.
([Commit](https://github.com/rails/rails/commit/4cb47167e747e8f9dc12b0ddaf82bdb68c03e032))
+* Added a `:required` option to singular associations, which defines a
+ presence validation on the association.
+ ([Pull Request](https://github.com/rails/rails/pull/16056))
+
Active Model
------------
-Please refer to the
-[Changelog](https://github.com/rails/rails/blob/4-2-stable/activemodel/CHANGELOG.md)
-for detailed changes.
+Please refer to the [Changelog][active-model] for detailed changes.
### Removals
@@ -283,9 +277,7 @@ for detailed changes.
Active Support
--------------
-Please refer to the
-[Changelog](https://github.com/rails/rails/blob/4-2-stable/activesupport/CHANGELOG.md)
-for detailed changes.
+Please refer to the [Changelog][active-support] for detailed changes.
### Removals
@@ -315,6 +307,11 @@ for detailed changes.
as well as `Kernel#concern` to avoid the `module Foo; extend ActiveSupport::Concern; end`
boilerplate. ([Commit](https://github.com/rails/rails/commit/b16c36e688970df2f96f793a759365b248b582ad))
+* Added `Hash#transform_values` and `Hash#transform_values!` to simplify a
+ common pattern where the values of a hash must change, but the keys are left
+ the same.
+ ([Pull Request](https://github.com/rails/rails/pull/15819))
+
Credits
-------
@@ -322,3 +319,11 @@ See the
[full list of contributors to Rails](http://contributors.rubyonrails.org/) for
the many people who spent many hours making Rails, the stable and robust
framework it is. Kudos to all of them.
+
+[railties]: https://github.com/rails/rails/blob/4-2-stable/railties/CHANGELOG.md
+[action-pack]: https://github.com/rails/rails/blob/4-2-stable/actionpack/CHANGELOG.md
+[action-view]: https://github.com/rails/rails/blob/4-2-stable/actionview/CHANGELOG.md
+[action-mailer]: https://github.com/rails/rails/blob/4-2-stable/actionmailer/CHANGELOG.md
+[active-record]: https://github.com/rails/rails/blob/4-2-stable/activerecord/CHANGELOG.md
+[active-model]: https://github.com/rails/rails/blob/4-2-stable/activemodel/CHANGELOG.md
+[active-support]: https://github.com/rails/rails/blob/4-2-stable/activesupport/CHANGELOG.md
diff --git a/guides/source/_welcome.html.erb b/guides/source/_welcome.html.erb
index 6ec3aa78a4..f84f1cb376 100644
--- a/guides/source/_welcome.html.erb
+++ b/guides/source/_welcome.html.erb
@@ -10,10 +10,10 @@
</p>
<% else %>
<p>
- These are the new guides for Rails 4.1 based on <a href="https://github.com/rails/rails/tree/<%= @version %>"><%= @version %></a>.
+ These are the new guides for Rails 4.2 based on <a href="https://github.com/rails/rails/tree/<%= @version %>"><%= @version %></a>.
These guides are designed to make you immediately productive with Rails, and to help you understand how all of the pieces fit together.
</p>
<% end %>
<p>
- The guides for earlier releases: <a href="http://guides.rubyonrails.org/v4.1.1/">Rails 4.1.1</a>, <a href="http://guides.rubyonrails.org/v4.0.5/">Rails 4.0.5</a>, <a href="http://guides.rubyonrails.org/v3.2.18/">Rails 3.2.18</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.4/">Rails 4.1.4</a>, <a href="http://guides.rubyonrails.org/v4.0.8/">Rails 4.0.8</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>.
</p>
diff --git a/guides/source/active_model_basics.md b/guides/source/active_model_basics.md
index 0019d08328..1131a83c36 100644
--- a/guides/source/active_model_basics.md
+++ b/guides/source/active_model_basics.md
@@ -198,3 +198,26 @@ person.valid? # => true
person.token = nil
person.valid? # => raises ActiveModel::StrictValidationFailed
```
+
+### ActiveModel::Naming
+
+Naming adds a number of class methods which make the naming and routing
+easier to manage. The module defines the `model_name` class method which
+will define a number of accessors using some `ActiveSupport::Inflector` methods.
+
+```ruby
+class Person
+ extend ActiveModel::Naming
+end
+
+Person.model_name.name # => "Person"
+Person.model_name.singular # => "person"
+Person.model_name.plural # => "people"
+Person.model_name.element # => "person"
+Person.model_name.human # => "Person"
+Person.model_name.collection # => "people"
+Person.model_name.param_key # => "person"
+Person.model_name.i18n_key # => :person
+Person.model_name.route_key # => "people"
+Person.model_name.singular_route_key # => "person"
+``` \ No newline at end of file
diff --git a/guides/source/active_record_validations.md b/guides/source/active_record_validations.md
index cb459626d5..7ec4ab312d 100644
--- a/guides/source/active_record_validations.md
+++ b/guides/source/active_record_validations.md
@@ -871,7 +871,7 @@ should happen, an `Array` can be used. Moreover, you can apply both `:if` and
```ruby
class Computer < ActiveRecord::Base
validates :mouse, presence: true,
- if: ["market.retail?", :desktop?]
+ if: ["market.retail?", :desktop?],
unless: Proc.new { |c| c.trackpad.present? }
end
```
diff --git a/guides/source/active_support_core_extensions.md b/guides/source/active_support_core_extensions.md
index 1329deeb16..5ed392d43d 100644
--- a/guides/source/active_support_core_extensions.md
+++ b/guides/source/active_support_core_extensions.md
@@ -3672,9 +3672,9 @@ t.advance(seconds: 1)
#### `Time.current`
-Active Support defines `Time.current` to be today in the current time zone. That's like `Time.now`, except that it honors the user time zone, if defined. It also defines `Time.yesterday` and `Time.tomorrow`, and the instance predicates `past?`, `today?`, and `future?`, all of them relative to `Time.current`.
+Active Support defines `Time.current` to be today in the current time zone. That's like `Time.now`, except that it honors the user time zone, if defined. It also defines the instance predicates `past?`, `today?`, and `future?`, all of them relative to `Time.current`.
-When making Time comparisons using methods which honor the user time zone, make sure to use `Time.current` and not `Time.now`. There are cases where the user time zone might be in the future compared to the system time zone, which `Time.today` uses by default. This means `Time.now` may equal `Time.yesterday`.
+When making Time comparisons using methods which honor the user time zone, make sure to use `Time.current` instead of `Time.now`. There are cases where the user time zone might be in the future compared to the system time zone, which `Time.now` uses by default. This means `Time.now.to_date` may equal `Date.yesterday`.
#### `all_day`, `all_week`, `all_month`, `all_quarter` and `all_year`
diff --git a/guides/source/command_line.md b/guides/source/command_line.md
index e283bcd0ef..cb0228fa75 100644
--- a/guides/source/command_line.md
+++ b/guides/source/command_line.md
@@ -62,7 +62,7 @@ With no further work, `rails server` will run our new shiny Rails app:
$ cd commandsapp
$ bin/rails server
=> Booting WEBrick
-=> Rails 4.0.0 application starting in development on http://0.0.0.0:3000
+=> Rails 4.2.0 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2013-08-07 02:00:01] INFO WEBrick 1.3.1
@@ -289,7 +289,7 @@ If you wish to test out some code without changing any data, you can do that by
```bash
$ bin/rails console --sandbox
-Loading development environment in sandbox (Rails 4.0.0)
+Loading development environment in sandbox (Rails 4.2.0)
Any modifications you make will be rolled back on exit
irb(main):001:0>
```
@@ -402,13 +402,13 @@ About your application's environment
Ruby version 1.9.3 (x86_64-linux)
RubyGems version 1.3.6
Rack version 1.3
-Rails version 4.1.1
+Rails version 4.2.0
JavaScript Runtime Node.js (V8)
-Active Record version 4.1.1
-Action Pack version 4.1.1
-Action View version 4.1.1
-Action Mailer version 4.1.1
-Active Support version 4.1.1
+Active Record version 4.2.0
+Action Pack version 4.2.0
+Action View version 4.2.0
+Action Mailer version 4.2.0
+Active Support version 4.2.0
Middleware Rack::Sendfile, ActionDispatch::Static, Rack::Lock, #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x007ffd131a7c88>, Rack::Runtime, Rack::MethodOverride, ActionDispatch::RequestId, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::DebugExceptions, ActionDispatch::RemoteIp, ActionDispatch::Reloader, ActionDispatch::Callbacks, ActiveRecord::Migration::CheckPending, ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::Head, Rack::ConditionalGet, Rack::ETag
Application root /home/foobar/commandsapp
Environment development
diff --git a/guides/source/debugging_rails_applications.md b/guides/source/debugging_rails_applications.md
index c1f26c2a5e..53b8566d83 100644
--- a/guides/source/debugging_rails_applications.md
+++ b/guides/source/debugging_rails_applications.md
@@ -309,7 +309,7 @@ For example:
```bash
=> Booting WEBrick
-=> Rails 4.1.1 application starting in development on http://0.0.0.0:3000
+=> Rails 4.2.0 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
=> Ctrl-C to shutdown server
@@ -422,11 +422,11 @@ then `backtrace` will supply the answer.
--> #0 ArticlesController.index
at /PathTo/project/test_app/app/controllers/articles_controller.rb:8
#1 ActionController::ImplicitRender.send_action(method#String, *args#Array)
- at /PathToGems/actionpack-4.1.1/lib/action_controller/metal/implicit_render.rb:4
+ at /PathToGems/actionpack-4.2.0/lib/action_controller/metal/implicit_render.rb:4
#2 AbstractController::Base.process_action(action#NilClass, *args#Array)
- at /PathToGems/actionpack-4.1.1/lib/abstract_controller/base.rb:189
+ at /PathToGems/actionpack-4.2.0/lib/abstract_controller/base.rb:189
#3 ActionController::Rendering.process_action(action#NilClass, *args#NilClass)
- at /PathToGems/actionpack-4.1.1/lib/action_controller/metal/rendering.rb:10
+ at /PathToGems/actionpack-4.2.0/lib/action_controller/metal/rendering.rb:10
...
```
@@ -438,7 +438,7 @@ context.
```
(byebug) frame 2
-[184, 193] in /PathToGems/actionpack-4.1.1/lib/abstract_controller/base.rb
+[184, 193] in /PathToGems/actionpack-4.2.0/lib/abstract_controller/base.rb
184: # is the intended way to override action dispatching.
185: #
186: # Notice that the first argument is the method to be dispatched
@@ -655,7 +655,7 @@ instruction to be executed. In this case, the activesupport's `week` method.
```
(byebug) step
-[50, 59] in /PathToGems/activesupport-4.1.1/lib/active_support/core_ext/numeric/time.rb
+[50, 59] in /PathToGems/activesupport-4.2.0/lib/active_support/core_ext/numeric/time.rb
50: ActiveSupport::Duration.new(self * 24.hours, [[:days, self]])
51: end
52: alias :day :days
diff --git a/guides/source/engines.md b/guides/source/engines.md
index e630e3d93b..a5f8ee27b8 100644
--- a/guides/source/engines.md
+++ b/guides/source/engines.md
@@ -31,10 +31,12 @@ Engines are also closely related to plugins. The two share a common `lib`
directory structure, and are both generated using the `rails plugin new`
generator. The difference is that an engine is considered a "full plugin" by
Rails (as indicated by the `--full` option that's passed to the generator
-command). This guide will refer to them simply as "engines" throughout. An
-engine **can** be a plugin, and a plugin **can** be an engine.
+command). We'll actually be using the `--mountable` option here, which includes
+all the features of `--full`, and then some. This guide will refer to these
+"full plugins" simply as "engines" throughout. An engine **can** be a plugin,
+and a plugin **can** be an engine.
-The engine that will be created in this guide will be called "blorgh". The
+The engine that will be created in this guide will be called "blorgh". This
engine will provide blogging functionality to its host applications, allowing
for new articles and comments to be created. At the beginning of this guide, you
will be working solely within the engine itself, but in later sections you'll
@@ -49,9 +51,8 @@ guide.
It's important to keep in mind at all times that the application should
**always** take precedence over its engines. An application is the object that
-has final say in what goes on in the universe (with the universe being the
-application's environment) where the engine should only be enhancing it, rather
-than changing it drastically.
+has final say in what goes on in its environment. The engine should
+only be enhancing it, rather than changing it drastically.
To see demonstrations of other engines, check out
[Devise](https://github.com/plataformatec/devise), an engine that provides
@@ -745,8 +746,9 @@ reason, the engine should not hardcode associations specifically for a `User`
class.
To keep it simple in this case, the application will have a class called `User`
-that represents the users of the application. It can be generated using this
-command inside the application:
+that represents the users of the application (we'll get into making this
+configurable further on). It can be generated using this command inside the
+application:
```bash
rails g model user name:string
diff --git a/guides/source/generators.md b/guides/source/generators.md
index 25c67de993..93fb5eece8 100644
--- a/guides/source/generators.md
+++ b/guides/source/generators.md
@@ -207,7 +207,7 @@ $ bin/rails generate scaffold User name:string
Looking at this output, it's easy to understand how generators work in Rails 3.0 and above. The scaffold generator doesn't actually generate anything, it just invokes others to do the work. This allows us to add/replace/remove any of those invocations. For instance, the scaffold generator invokes the scaffold_controller generator, which invokes erb, test_unit and helper generators. Since each generator has a single responsibility, they are easy to reuse, avoiding code duplication.
-Our first customization on the workflow will be to stop generating stylesheets, javascripts and test fixtures for scaffolds. We can achieve that by changing our configuration to the following:
+Our first customization on the workflow will be to stop generating stylesheet, JavaScript and test fixture files for scaffolds. We can achieve that by changing our configuration to the following:
```ruby
config.generators do |g|
@@ -219,7 +219,7 @@ config.generators do |g|
end
```
-If we generate another resource with the scaffold generator, we can see that stylesheets, javascripts and fixtures are not created anymore. If you want to customize it further, for example to use DataMapper and RSpec instead of Active Record and TestUnit, it's just a matter of adding their gems to your application and configuring your generators.
+If we generate another resource with the scaffold generator, we can see that stylesheet, JavaScript and fixture files are not created anymore. If you want to customize it further, for example to use DataMapper and RSpec instead of Active Record and TestUnit, it's just a matter of adding their gems to your application and configuring your generators.
To demonstrate this, we are going to create a new helper generator that simply adds some instance variable readers. First, we create a generator within the rails namespace, as this is where rails searches for generators used as hooks:
diff --git a/guides/source/getting_started.md b/guides/source/getting_started.md
index 669e1eefac..0e121b6f75 100644
--- a/guides/source/getting_started.md
+++ b/guides/source/getting_started.md
@@ -123,7 +123,7 @@ run the following:
$ bin/rails --version
```
-If it says something like "Rails 4.1.1", you are ready to continue.
+If it says something like "Rails 4.2.0", you are ready to continue.
### Creating the Blog Application
diff --git a/guides/source/i18n.md b/guides/source/i18n.md
index e9da4983e1..1023598aa4 100644
--- a/guides/source/i18n.md
+++ b/guides/source/i18n.md
@@ -437,11 +437,11 @@ TIP: Right now you might need to add some more date/time formats in order to mak
### Inflection Rules For Other Locales
-Rails 4.0 allows you to define inflection rules (such as rules for singularization and pluralization) for locales other than English. In `config/initializers/inflections.rb`, you can define these rules for multiple locales. The initializer contains a default example for specifying additional rules for English; follow that format for other locales as you see fit.
+Rails allows you to define inflection rules (such as rules for singularization and pluralization) for locales other than English. In `config/initializers/inflections.rb`, you can define these rules for multiple locales. The initializer contains a default example for specifying additional rules for English; follow that format for other locales as you see fit.
### Localized Views
-Rails 2.3 introduces another convenient localization feature: localized views (templates). Let's say you have a _BooksController_ in your application. Your _index_ action renders content in `app/views/books/index.html.erb` template. When you put a _localized variant_ of this template: `index.es.html.erb` in the same directory, Rails will render content in this template, when the locale is set to `:es`. When the locale is set to the default locale, the generic `index.html.erb` view will be used. (Future Rails versions may well bring this _automagic_ localization to assets in `public`, etc.)
+Let's say you have a _BooksController_ in your application. Your _index_ action renders content in `app/views/books/index.html.erb` template. When you put a _localized variant_ of this template: `index.es.html.erb` in the same directory, Rails will render content in this template, when the locale is set to `:es`. When the locale is set to the default locale, the generic `index.html.erb` view will be used. (Future Rails versions may well bring this _automagic_ localization to assets in `public`, etc.)
You can make use of this feature, e.g. when working with a large amount of static content, which would be clumsy to put inside YAML or Ruby dictionaries. Bear in mind, though, that any change you would like to do later to the template must be propagated to all of them.
diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md
index 9c67391e8f..1e752b449d 100644
--- a/guides/source/upgrading_ruby_on_rails.md
+++ b/guides/source/upgrading_ruby_on_rails.md
@@ -432,6 +432,20 @@ symbol access is no longer supported. This is also the case for
`store_accessors` based on top of `json` or `hstore` columns. Make sure to use
string keys consistently.
+### Explicit block use for `ActiveSupport::Callbacks`
+
+Rails 4.1 now expects an explicit block to be passed when calling
+`ActiveSupport::Callbacks.set_callback`. This change stems from
+`ActiveSupport::Callbacks` being largely rewritten for the 4.1 release.
+
+```ruby
+# Previously in Rails 4.0
+set_callback :save, :around, ->(r, &block) { stuff; result = block.call; stuff }
+
+# Now in Rails 4.1
+set_callback :save, :around, ->(r, block) { stuff; result = block.call; stuff }
+```
+
Upgrading from Rails 3.2 to Rails 4.0
-------------------------------------