rails 4.0.0.beta1 → 4.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rails might be problematic. Click here for more details.

Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +78 -0
  3. data/guides/CHANGELOG.md +3 -0
  4. data/guides/assets/images/getting_started/unknown_action_create_for_posts.png +0 -0
  5. data/guides/bug_report_templates/active_record_gem.rb +37 -0
  6. data/guides/bug_report_templates/active_record_master.rb +48 -0
  7. data/guides/code/getting_started/Gemfile +16 -11
  8. data/guides/code/getting_started/app/controllers/comments_controller.rb +2 -2
  9. data/guides/code/getting_started/app/controllers/posts_controller.rb +2 -2
  10. data/guides/code/getting_started/config/application.rb +3 -2
  11. data/guides/code/getting_started/config/initializers/session_store.rb +1 -1
  12. data/guides/code/getting_started/config/routes.rb +2 -2
  13. data/guides/code/getting_started/public/404.html +41 -10
  14. data/guides/code/getting_started/public/422.html +42 -10
  15. data/guides/code/getting_started/public/500.html +41 -10
  16. data/guides/rails_guides/markdown/renderer.rb +1 -1
  17. data/guides/source/2_2_release_notes.md +15 -15
  18. data/guides/source/4_0_release_notes.md +1 -7
  19. data/guides/source/action_controller_overview.md +176 -22
  20. data/guides/source/action_mailer_basics.md +246 -141
  21. data/guides/source/action_view_overview.md +3 -8
  22. data/guides/source/active_record_basics.md +98 -95
  23. data/guides/source/active_record_querying.md +90 -17
  24. data/guides/source/active_record_validations.md +41 -0
  25. data/guides/source/active_support_core_extensions.md +23 -3
  26. data/guides/source/active_support_instrumentation.md +6 -6
  27. data/guides/source/asset_pipeline.md +1 -1
  28. data/guides/source/association_basics.md +34 -10
  29. data/guides/source/caching_with_rails.md +2 -7
  30. data/guides/source/command_line.md +7 -7
  31. data/guides/source/configuring.md +3 -3
  32. data/guides/source/contributing_to_ruby_on_rails.md +38 -5
  33. data/guides/source/credits.html.erb +1 -1
  34. data/guides/source/debugging_rails_applications.md +19 -22
  35. data/guides/source/development_dependencies_install.md +2 -2
  36. data/guides/source/documents.yaml +5 -1
  37. data/guides/source/engines.md +21 -16
  38. data/guides/source/form_helpers.md +28 -7
  39. data/guides/source/generators.md +2 -2
  40. data/guides/source/getting_started.md +14 -13
  41. data/guides/source/i18n.md +22 -0
  42. data/guides/source/initialization.md +1 -1
  43. data/guides/source/layouts_and_rendering.md +60 -4
  44. data/guides/source/migrations.md +27 -2
  45. data/guides/source/rails_application_templates.md +11 -11
  46. data/guides/source/rails_on_rack.md +9 -6
  47. data/guides/source/routing.md +19 -3
  48. data/guides/source/ruby_on_rails_guides_guidelines.md +1 -1
  49. data/guides/source/security.md +2 -2
  50. data/guides/source/testing.md +106 -85
  51. data/guides/source/upgrading_ruby_on_rails.md +112 -9
  52. data/guides/source/working_with_javascript_in_rails.md +1 -0
  53. metadata +17 -16
  54. data/README.rdoc +0 -77
  55. data/guides/code/getting_started/app/assets/images/rails.png +0 -0
@@ -23,7 +23,7 @@ One common task is to inspect the contents of a variable. In Rails, you can do t
23
23
 
24
24
  ### `debug`
25
25
 
26
- The `debug` helper will return a \<pre>-tag that renders the object using the YAML format. This will generate human-readable data from any object. For example, if you have this code in a view:
26
+ The `debug` helper will return a \<pre> tag that renders the object using the YAML format. This will generate human-readable data from any object. For example, if you have this code in a view:
27
27
 
28
28
  ```html+erb
29
29
  <%= debug @post %>
@@ -174,7 +174,7 @@ class PostsController < ApplicationController
174
174
  end
175
175
  ```
176
176
 
177
- Here's an example of the log generated by this method:
177
+ Here's an example of the log generated when this controller action is executed:
178
178
 
179
179
  ```
180
180
  Processing PostsController#create (for 127.0.0.1 at 2008-09-08 11:52:54) [POST]
@@ -194,11 +194,11 @@ Redirected to #<Post:0x20af760>
194
194
  Completed in 0.01224 (81 reqs/sec) | DB: 0.00044 (3%) | 302 Found [http://localhost/posts]
195
195
  ```
196
196
 
197
- Adding extra logging like this makes it easy to search for unexpected or unusual behavior in your logs. If you add extra logging, be sure to make sensible use of log levels, to avoid filling your production logs with useless trivia.
197
+ Adding extra logging like this makes it easy to search for unexpected or unusual behavior in your logs. If you add extra logging, be sure to make sensible use of log levels to avoid filling your production logs with useless trivia.
198
198
 
199
199
  ### Tagged Logging
200
200
 
201
- When running multi-user, multi-account applications, it’s often useful to be able to filter the logs using some custom rules. `TaggedLogging` in Active Support helps in doing exactly that by stamping log lines with subdomains, request ids, and anything else to aid debugging such applications.
201
+ When running multi-user, multi-account applications, it’s often useful to be able to filter the logs using some custom rules. `TaggedLogging` in ActiveSupport helps in doing exactly that by stamping log lines with subdomains, request ids, and anything else to aid debugging such applications.
202
202
 
203
203
  ```ruby
204
204
  logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
@@ -216,7 +216,7 @@ The debugger can also help you if you want to learn about the Rails source code
216
216
 
217
217
  ### Setup
218
218
 
219
- Rails uses the `debugger` gem to set breakpoints and step through live code. To install it, just run:
219
+ You can use the `debugger` gem to set breakpoints and step through live code in Rails. To install it, just run:
220
220
 
221
221
  ```bash
222
222
  $ gem install debugger
@@ -235,7 +235,7 @@ class PeopleController < ApplicationController
235
235
  end
236
236
  ```
237
237
 
238
- If you see the message in the console or logs:
238
+ If you see this message in the console or logs:
239
239
 
240
240
  ```
241
241
  ***** Debugger requested, but was not available: Start server with --debugger to enable *****
@@ -246,12 +246,12 @@ Make sure you have started your web server with the option `--debugger`:
246
246
  ```bash
247
247
  $ rails server --debugger
248
248
  => Booting WEBrick
249
- => Rails 3.0.0 application starting on http://0.0.0.0:3000
249
+ => Rails 3.2.13 application starting on http://0.0.0.0:3000
250
250
  => Debugger enabled
251
251
  ...
252
252
  ```
253
253
 
254
- TIP: In development mode, you can dynamically `require \'debugger\'` instead of restarting the server, if it was started without `--debugger`.
254
+ TIP: In development mode, you can dynamically `require \'debugger\'` instead of restarting the server, even if it was started without `--debugger`.
255
255
 
256
256
  ### The Shell
257
257
 
@@ -266,7 +266,7 @@ For example:
266
266
  (rdb:7)
267
267
  ```
268
268
 
269
- Now it's time to explore and dig into your application. A good place to start is by asking the debugger for help... so type: `help` (You didn't see that coming, right?)
269
+ Now it's time to explore and dig into your application. A good place to start is by asking the debugger for help. Type: `help`
270
270
 
271
271
  ```
272
272
  (rdb:7) help
@@ -281,7 +281,7 @@ condition down finish list ps save thread var
281
281
  continue edit frame method putl set tmate where
282
282
  ```
283
283
 
284
- TIP: To view the help menu for any command use `help <command-name>` in active debug mode. For example: _`help var`_
284
+ TIP: To view the help menu for any command use `help <command-name>` at the debugger prompt. For example: _`help var`_
285
285
 
286
286
  The next command to learn is one of the most useful: `list`. You can abbreviate any debugging command by supplying just enough letters to distinguish them from other commands, so you can also use `l` for the `list` command.
287
287
 
@@ -289,7 +289,7 @@ This command shows you where you are in the code by printing 10 lines centered a
289
289
 
290
290
  ```
291
291
  (rdb:7) list
292
- [1, 10] in /PathToProject/posts_controller.rb
292
+ [1, 10] in /PathTo/project/app/controllers/posts_controller.rb
293
293
  1 class PostsController < ApplicationController
294
294
  2 # GET /posts
295
295
  3 # GET /posts.json
@@ -325,7 +325,7 @@ On the other hand, to see the previous ten lines you should type `list-` (or `l-
325
325
 
326
326
  ```
327
327
  (rdb:7) l-
328
- [1, 10] in /PathToProject/posts_controller.rb
328
+ [1, 10] in /PathTo/project/app/controllers/posts_controller.rb
329
329
  1 class PostsController < ApplicationController
330
330
  2 # GET /posts
331
331
  3 # GET /posts.json
@@ -343,7 +343,7 @@ Finally, to see where you are in the code again you can type `list=`
343
343
 
344
344
  ```
345
345
  (rdb:7) list=
346
- [1, 10] in /PathToProject/posts_controller.rb
346
+ [1, 10] in /PathTo/project/app/controllers/posts_controller.rb
347
347
  1 class PostsController < ApplicationController
348
348
  2 # GET /posts
349
349
  3 # GET /posts.json
@@ -502,7 +502,7 @@ TIP: You can use the debugger while using `rails console`. Just remember to `req
502
502
 
503
503
  ```
504
504
  $ rails console
505
- Loading development environment (Rails 3.1.0)
505
+ Loading development environment (Rails 3.2.13)
506
506
  >> require "debugger"
507
507
  => []
508
508
  >> author = Author.first
@@ -655,21 +655,18 @@ Plugins for Debugging
655
655
 
656
656
  There are some Rails plugins to help you to find errors and debug your application. Here is a list of useful plugins for debugging:
657
657
 
658
- * [Footnotes](https://github.com/josevalim/rails-footnotes:) Every Rails page has footnotes that give request information and link back to your source via TextMate.
659
- * [Query Trace](https://github.com/ntalbott/query_trace/tree/master:) Adds query origin tracing to your logs.
660
- * [Query Reviewer](https://github.com/nesquena/query_reviewer:) This rails plugin not only runs "EXPLAIN" before each of your select queries in development, but provides a small DIV in the rendered output of each page with the summary of warnings for each query that it analyzed.
661
- * [Exception Notifier](https://github.com/smartinez87/exception_notification/tree/master:) Provides a mailer object and a default set of templates for sending email notifications when errors occur in a Rails application.
658
+ * [Footnotes](https://github.com/josevalim/rails-footnotes) Every Rails page has footnotes that give request information and link back to your source via TextMate.
659
+ * [Query Trace](https://github.com/ntalbott/query_trace/tree/master) Adds query origin tracing to your logs.
660
+ * [Query Reviewer](https://github.com/nesquena/query_reviewer) This rails plugin not only runs "EXPLAIN" before each of your select queries in development, but provides a small DIV in the rendered output of each page with the summary of warnings for each query that it analyzed.
661
+ * [Exception Notifier](https://github.com/smartinez87/exception_notification/tree/master) Provides a mailer object and a default set of templates for sending email notifications when errors occur in a Rails application.
662
662
 
663
663
  References
664
664
  ----------
665
665
 
666
666
  * [ruby-debug Homepage](http://bashdb.sourceforge.net/ruby-debug/home-page.html)
667
667
  * [debugger Homepage](https://github.com/cldwalker/debugger)
668
- * [Article: Debugging a Rails application with ruby-debug](http://www.sitepoint.com/article/debug-rails-app-ruby-debug/)
669
- * [ruby-debug Basics screencast](http://brian.maybeyoureinsane.net/blog/2007/05/07/ruby-debug-basics-screencast/)
668
+ * [Article: Debugging a Rails application with ruby-debug](http://www.sitepoint.com/debug-rails-app-ruby-debug/)
670
669
  * [Ryan Bates' debugging ruby (revised) screencast](http://railscasts.com/episodes/54-debugging-ruby-revised)
671
670
  * [Ryan Bates' stack trace screencast](http://railscasts.com/episodes/24-the-stack-trace)
672
671
  * [Ryan Bates' logger screencast](http://railscasts.com/episodes/56-the-logger)
673
672
  * [Debugging with ruby-debug](http://bashdb.sourceforge.net/ruby-debug.html)
674
- * [ruby-debug cheat sheet](http://cheat.errtheblog.com/s/rdebug/)
675
- * [Ruby on Rails Wiki: How to Configure Logging](http://wiki.rubyonrails.org/rails/pages/HowtoConfigureLogging)
@@ -21,9 +21,9 @@ In case you can't use the Rails development box, see section above, these are th
21
21
 
22
22
  Ruby on Rails uses Git for source code control. The [Git homepage](http://git-scm.com/) has installation instructions. There are a variety of resources on the net that will help you get familiar with Git:
23
23
 
24
- * [Try Git course](http://try.github.com/) is an interactive course that will teach you the basics.
24
+ * [Try Git course](http://try.github.io/) is an interactive course that will teach you the basics.
25
25
  * The [official Documentation](http://git-scm.com/documentation) is pretty comprehensive and also contains some videos with the basics of Git
26
- * [Everyday Git](http://schacon.github.com/git/everyday.html) will teach you just enough about Git to get by.
26
+ * [Everyday Git](http://schacon.github.io/git/everyday.html) will teach you just enough about Git to get by.
27
27
  * The [PeepCode screencast](https://peepcode.com/products/git) on Git ($9) is easier to follow.
28
28
  * [GitHub](http://help.github.com) offers links to a variety of Git resources.
29
29
  * [Pro Git](http://git-scm.com/book) is an entire book about Git with a Creative Commons license.
@@ -35,6 +35,11 @@
35
35
  -
36
36
  name: Views
37
37
  documents:
38
+ -
39
+ name: Action View Overview
40
+ url: action_view_overview.html
41
+ description: This guide provides an introduction to Action View and introduces a few of the more common view helpers.
42
+ work_in_progress: true
38
43
  -
39
44
  name: Layouts and Rendering in Rails
40
45
  url: layouts_and_rendering.html
@@ -68,7 +73,6 @@
68
73
  -
69
74
  name: Action Mailer Basics
70
75
  url: action_mailer_basics.html
71
- work_in_progress: true
72
76
  description: This guide describes how to use Action Mailer to send and receive emails.
73
77
  -
74
78
  name: Testing Rails Applications
@@ -461,7 +461,7 @@ NOTE: Other engines, such as Devise, handle this a little differently by making
461
461
  The engine contains migrations for the `blorgh_posts` and `blorgh_comments` table which need to be created in the application's database so that the engine's models can query them correctly. To copy these migrations into the application use this command:
462
462
 
463
463
  ```bash
464
- $ rake blorgh:install:migrations
464
+ $ rake blorgh_engine:install:migrations
465
465
  ```
466
466
 
467
467
  If you have multiple engines that need migrations copied over, use `railties:install:migrations` instead:
@@ -612,50 +612,50 @@ This section covers how to make the `User` class configurable, followed by gener
612
612
 
613
613
  #### Setting configuration settings in the application
614
614
 
615
- The next step is to make the class that represents a `User` in the application customizable for the engine. This is because, as explained before, that class may not always be `User`. To make this customizable, the engine will have a configuration setting called `user_class` that will be used to specify what the class representing users is inside the application.
615
+ The next step is to make the class that represents a `User` in the application customizable for the engine. This is because, as explained before, that class may not always be `User`. To make this customizable, the engine will have a configuration setting called `author_class` that will be used to specify what the class representing users is inside the application.
616
616
 
617
617
  To define this configuration setting, you should use a `mattr_accessor` inside the `Blorgh` module for the engine, located at `lib/blorgh.rb` inside the engine. Inside this module, put this line:
618
618
 
619
619
  ```ruby
620
- mattr_accessor :user_class
620
+ mattr_accessor :author_class
621
621
  ```
622
622
 
623
- This method works like its brothers `attr_accessor` and `cattr_accessor`, but provides a setter and getter method on the module with the specified name. To use it, it must be referenced using `Blorgh.user_class`.
623
+ This method works like its brothers `attr_accessor` and `cattr_accessor`, but provides a setter and getter method on the module with the specified name. To use it, it must be referenced using `Blorgh.author_class`.
624
624
 
625
625
  The next step is switching the `Blorgh::Post` model over to this new setting. For the `belongs_to` association inside this model (`app/models/blorgh/post.rb`), it will now become this:
626
626
 
627
627
  ```ruby
628
- belongs_to :author, class_name: Blorgh.user_class
628
+ belongs_to :author, class_name: Blorgh.author_class
629
629
  ```
630
630
 
631
631
  The `set_author` method also located in this class should also use this class:
632
632
 
633
633
  ```ruby
634
- self.author = Blorgh.user_class.constantize.find_or_create_by(name: author_name)
634
+ self.author = Blorgh.author_class.constantize.find_or_create_by(name: author_name)
635
635
  ```
636
636
 
637
- To save having to call `constantize` on the `user_class` result all the time, you could instead just override the `user_class` getter method inside the `Blorgh` module in the `lib/blorgh.rb` file to always call `constantize` on the saved value before returning the result:
637
+ To save having to call `constantize` on the `author_class` result all the time, you could instead just override the `author_class` getter method inside the `Blorgh` module in the `lib/blorgh.rb` file to always call `constantize` on the saved value before returning the result:
638
638
 
639
639
  ```ruby
640
- def self.user_class
641
- @@user_class.constantize
640
+ def self.author_class
641
+ @@author_class.constantize
642
642
  end
643
643
  ```
644
644
 
645
645
  This would then turn the above code for `set_author` into this:
646
646
 
647
647
  ```ruby
648
- self.author = Blorgh.user_class.find_or_create_by(name: author_name)
648
+ self.author = Blorgh.author_class.find_or_create_by(name: author_name)
649
649
  ```
650
650
 
651
- Resulting in something a little shorter, and more implicit in its behavior. The `user_class` method should always return a `Class` object.
651
+ Resulting in something a little shorter, and more implicit in its behavior. The `author_class` method should always return a `Class` object.
652
652
 
653
- Since we changed the `user_class` method to no longer return a
653
+ Since we changed the `author_class` method to no longer return a
654
654
  `String` but a `Class` we must also modify our `belongs_to` definition
655
655
  in the `Blorgh::Post` model:
656
656
 
657
657
  ```ruby
658
- belongs_to :author, class_name: Blorgh.user_class.to_s
658
+ belongs_to :author, class_name: Blorgh.author_class.to_s
659
659
  ```
660
660
 
661
661
  To set this configuration setting within the application, an initializer should be used. By using an initializer, the configuration will be set up before the application starts and calls the engine's models which may depend on this configuration setting existing.
@@ -663,7 +663,7 @@ To set this configuration setting within the application, an initializer should
663
663
  Create a new initializer at `config/initializers/blorgh.rb` inside the application where the `blorgh` engine is installed and put this content in it:
664
664
 
665
665
  ```ruby
666
- Blorgh.user_class = "User"
666
+ Blorgh.author_class = "User"
667
667
  ```
668
668
 
669
669
  WARNING: It's very important here to use the `String` version of the class, rather than the class itself. If you were to use the class, Rails would attempt to load that class and then reference the related table, which could lead to problems if the table wasn't already existing. Therefore, a `String` should be used and then converted to a class using `constantize` in the engine later on.
@@ -676,7 +676,12 @@ There are now no strict dependencies on what the class is, only what the API for
676
676
 
677
677
  Within an engine, there may come a time where you wish to use things such as initializers, internationalization or other configuration options. The great news is that these things are entirely possible because a Rails engine shares much the same functionality as a Rails application. In fact, a Rails application's functionality is actually a superset of what is provided by engines!
678
678
 
679
- If you wish to use an initializer — code that should run before the engine is loaded — the place for it is the `config/initializers` folder. This directory's functionality is explained in the [Initializers section](http://guides.rubyonrails.org/configuring.html#initializers) of the Configuring guide, and works precisely the same way as the `config/initializers` directory inside an application. Same goes for if you want to use a standard initializer.
679
+ If you wish to use an initializer — code that should run before the engine is
680
+ loaded — the place for it is the `config/initializers` folder. This directory's
681
+ functionality is explained in the
682
+ [Initializers section](configuring.html#initializers) of the Configuring guide,
683
+ and works precisely the same way as the `config/initializers` directory inside
684
+ an application. Same goes for if you want to use a standard initializer.
680
685
 
681
686
  For locales, simply place the locale files in the `config/locales` directory, just like you would in an application.
682
687
 
@@ -918,7 +923,7 @@ initializer "blorgh.assets.precompile" do |app|
918
923
  end
919
924
  ```
920
925
 
921
- For more information, read the [Asset Pipeline guide](http://guides.rubyonrails.org/asset_pipeline.html)
926
+ For more information, read the [Asset Pipeline guide](asset_pipeline.html)
922
927
 
923
928
  ### Other gem dependencies
924
929
 
@@ -221,7 +221,7 @@ Upon form submission the value entered by the user will be stored in `params[:pe
221
221
 
222
222
  WARNING: You must pass the name of an instance variable, i.e. `:person` or `"person"`, not an actual instance of your model object.
223
223
 
224
- Rails provides helpers for displaying the validation errors associated with a model object. These are covered in detail by the [Active Record Validations and Callbacks](./active_record_validations_callbacks.html#displaying-validation-errors-in-the-view) guide.
224
+ Rails provides helpers for displaying the validation errors associated with a model object. These are covered in detail by the [Active Record Validations](./active_record_validations.html#displaying-validation-errors-in-views) guide.
225
225
 
226
226
  ### Binding a Form to an Object
227
227
 
@@ -423,7 +423,7 @@ Whenever Rails sees that the internal value of an option being generated matches
423
423
 
424
424
  TIP: The second argument to `options_for_select` must be exactly equal to the desired internal value. In particular if the value is the integer 2 you cannot pass "2" to `options_for_select` — you must pass 2. Be aware of values extracted from the `params` hash as they are all strings.
425
425
 
426
- WARNING: when `:inlude_blank` or `:prompt:` are not present, `:include_blank` is forced true if the select attribute `required` is true, display `size` is one and `multiple` is not true.
426
+ WARNING: when `:include_blank` or `:prompt` are not present, `:include_blank` is forced true if the select attribute `required` is true, display `size` is one and `multiple` is not true.
427
427
 
428
428
  You can add arbitrary attributes to the options using hashes:
429
429
 
@@ -836,17 +836,14 @@ Active Record provides model level support via the `accepts_nested_attributes_f
836
836
  class Person < ActiveRecord::Base
837
837
  has_many :addresses
838
838
  accepts_nested_attributes_for :addresses
839
-
840
- attr_accessible :name, :addresses_attributes
841
839
  end
842
840
 
843
841
  class Address < ActiveRecord::Base
844
842
  belongs_to :person
845
- attr_accessible :kind, :street
846
843
  end
847
844
  ```
848
845
 
849
- This creates an `addresses_attributes=` method on `Person` that allows you to create, update and (optionally) destroy addresses. When using `attr_accessible` or `attr_protected` you must mark `addresses_attributes` as accessible as well as the other attributes of `Person` and `Address` that should be mass assigned.
846
+ This creates an `addresses_attributes=` method on `Person` that allows you to create, update and (optionally) destroy addresses.
850
847
 
851
848
  ### Building the Form
852
849
 
@@ -906,7 +903,21 @@ If the associated object is already saved, `fields_for` autogenerates a hidden i
906
903
 
907
904
  ### The Controller
908
905
 
909
- You do not need to write any specific controller code to use nested attributes. Create and update records as you would with a simple form.
906
+ As usual you need to
907
+ [whitelist the parameters](action_controller_overview.html#strong-parameters) in
908
+ the controller before you pass them to the model:
909
+
910
+ ```ruby
911
+ def create
912
+ @person = Person.new(person_params)
913
+ # ...
914
+ end
915
+
916
+ private
917
+ def person_params
918
+ params.require(:person).permit(:name, addresses_attributes: [:id, :kind, :street])
919
+ end
920
+ ```
910
921
 
911
922
  ### Removing Objects
912
923
 
@@ -937,6 +948,16 @@ If the hash of attributes for an object contains the key `_destroy` with a value
937
948
  <% end %>
938
949
  ```
939
950
 
951
+ Don't forget to update the whitelisted params in your controller to also include
952
+ the `_destroy` field:
953
+
954
+ ```ruby
955
+ def person_params
956
+ params.require(:person).
957
+ permit(:name, addresses_attributes: [:id, :kind, :street, :_destroy])
958
+ end
959
+ ```
960
+
940
961
  ### Preventing Empty Records
941
962
 
942
963
  It is often useful to ignore sets of fields that the user has not filled in. You can control this by passing a `:reject_if` proc to `accepts_nested_attributes_for`. This proc will be called with each hash of attributes submitted by the form. If the proc returns `false` then Active Record will not build an associated object for that hash. The example below only tries to build an address if the `kind` attribute is set.
@@ -589,11 +589,11 @@ Creates an initializer in the `config/initializers` directory of the application
589
589
  initializer "begin.rb", "puts 'this is the beginning'"
590
590
  ```
591
591
 
592
- This method also takes a block:
592
+ This method also takes a block, expected to return a string:
593
593
 
594
594
  ```ruby
595
595
  initializer "begin.rb" do
596
- puts "Almost done!"
596
+ "puts 'this is the beginning'"
597
597
  end
598
598
  ```
599
599
 
@@ -103,7 +103,7 @@ To verify that you have everything installed correctly, you should be able to ru
103
103
  $ rails --version
104
104
  ```
105
105
 
106
- If it says something like "Rails 3.2.9", you are ready to continue.
106
+ If it says something like "Rails 4.0.0", you are ready to continue.
107
107
 
108
108
  ### Creating the Blog Application
109
109
 
@@ -208,7 +208,7 @@ create app/assets/stylesheets/welcome.css.scss
208
208
 
209
209
  Most important of these are of course the controller, located at `app/controllers/welcome_controller.rb` and the view, located at `app/views/welcome/index.html.erb`.
210
210
 
211
- Open the `app/views/welcome/index.html.erb` file in your text editor and edit it to contain a single line of code:
211
+ Open the `app/views/welcome/index.html.erb` file in your text editor. Delete all of the existing code in the file, and replace it with the following single line of code:
212
212
 
213
213
  ```html
214
214
  <h1>Hello, Rails!</h1>
@@ -278,7 +278,7 @@ With the route defined, requests can now be made to `/posts/new` in the applicat
278
278
 
279
279
  ![Another routing error, uninitialized constant PostsController](images/getting_started/routing_error_no_controller.png)
280
280
 
281
- This error is happening because this route need a controller to be defined. The route is attempting to find that controller so it can serve the request, but with the controller undefined, it just can't do that. The solution to this particular problem is simple: you need to create a controller called `PostsController`. You can do this by running this command:
281
+ This error occurs because the route needs to have a controller defined in order to serve the request. The solution to this particular problem is simple: create a controller called `PostsController`. You can do this by running this command:
282
282
 
283
283
  ```bash
284
284
  $ rails g controller posts
@@ -568,7 +568,7 @@ interested in. We also use an instance variable (prefixed by `@`) to
568
568
  hold a reference to the post object. We do this because Rails will pass all instance
569
569
  variables to the view.
570
570
 
571
- Now, create a new file `app/view/posts/show.html.erb` with the following
571
+ Now, create a new file `app/views/posts/show.html.erb` with the following
572
572
  content:
573
573
 
574
574
  ```html+erb
@@ -1043,7 +1043,7 @@ REST convention, so to create a new `Post` object it will look for a
1043
1043
  route named `posts_path`, and to update a `Post` object it will look for
1044
1044
  a route named `post_path` and pass the current object. Similarly, rails
1045
1045
  knows that it should create new objects via POST and update them via
1046
- PUT.
1046
+ PATCH.
1047
1047
 
1048
1048
  If you run `rake routes` from the console you'll see that we already
1049
1049
  have a `posts_path` route, which was created automatically by Rails when we
@@ -1054,13 +1054,13 @@ received an error before. With your server running you can view your routes by v
1054
1054
  ```bash
1055
1055
  $ rake routes
1056
1056
 
1057
- posts GET /posts(.:format) posts#index
1058
- posts_new GET /posts/new(.:format) posts#new
1059
- POST /posts(.:format) posts#create
1060
- GET /posts/:id(.:format) posts#show
1061
- GET /posts/:id/edit(.:format) posts#edit
1062
- PUT /posts/:id(.:format) posts#update
1063
- root / welcome#index
1057
+ posts GET /posts(.:format) posts#index
1058
+ posts_new GET /posts/new(.:format) posts#new
1059
+ POST /posts(.:format) posts#create
1060
+ GET /posts/:id(.:format) posts#show
1061
+ GET /posts/:id/edit(.:format) posts#edit
1062
+ PATCH /posts/:id(.:format) posts#update
1063
+ root / welcome#index
1064
1064
  ```
1065
1065
 
1066
1066
  To fix this, open `config/routes.rb` and modify the `get "posts/:id"`
@@ -1197,6 +1197,7 @@ $ rake routes
1197
1197
  new_post GET /posts/new(.:format) posts#new
1198
1198
  edit_post GET /posts/:id/edit(.:format) posts#edit
1199
1199
  post GET /posts/:id(.:format) posts#show
1200
+ PATCH /posts/:id(.:format) posts#update
1200
1201
  PUT /posts/:id(.:format) posts#update
1201
1202
  DELETE /posts/:id(.:format) posts#destroy
1202
1203
  root / welcome#index
@@ -1761,7 +1762,7 @@ cannot be automatically detected by Rails and corrected.
1761
1762
 
1762
1763
  Two very common sources of data that are not UTF-8:
1763
1764
 
1764
- * Your text editor: Most text editors (such as Textmate), default to saving files as
1765
+ * Your text editor: Most text editors (such as TextMate), default to saving files as
1765
1766
  UTF-8. If your text editor does not, this can result in special characters that you
1766
1767
  enter in your templates (such as é) to appear as a diamond with a question mark inside
1767
1768
  in the browser. This also applies to your i18n translation files.
@@ -837,6 +837,28 @@ en:
837
837
  NOTE: In order to use this helper, you need to install [DynamicForm](https://github.com/joelmoss/dynamic_form)
838
838
  gem by adding this line to your Gemfile: `gem 'dynamic_form'`.
839
839
 
840
+ ### Translations for Action Mailer E-Mail Subjects
841
+
842
+ If you don't pass a subject to the `mail` method, Action Mailer will try to find
843
+ it in your translations. The performed lookup will use the pattern
844
+ `<mailer_scope>.<action_name>.subject` to construct the key.
845
+
846
+ ```ruby
847
+ # user_mailer.rb
848
+ class UserMailer < ActionMailer::Base
849
+ def welcome(user)
850
+ #...
851
+ end
852
+ end
853
+ ```
854
+
855
+ ```yaml
856
+ en:
857
+ user_mailer:
858
+ welcome:
859
+ subject: "Welcome to Rails Guides!"
860
+ ```
861
+
840
862
  ### Overview of Other Built-In Methods that Provide I18n Support
841
863
 
842
864
  Rails uses fixed strings and other localizations, such as format strings and other format information in a couple of helpers. Here's a brief overview.