rails 4.0.13 → 4.1.0.beta1

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 (95) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +20 -15
  3. data/guides/CHANGELOG.md +5 -74
  4. data/guides/assets/images/edge_badge.png +0 -0
  5. data/guides/assets/images/feature_tile.gif +0 -0
  6. data/guides/assets/images/footer_tile.gif +0 -0
  7. data/guides/assets/images/fxn.png +0 -0
  8. data/guides/assets/images/getting_started/challenge.png +0 -0
  9. data/guides/assets/images/getting_started/forbidden_attributes_for_new_post.png +0 -0
  10. data/guides/assets/images/getting_started/new_post.png +0 -0
  11. data/guides/assets/images/getting_started/routing_error_no_controller.png +0 -0
  12. data/guides/assets/images/getting_started/routing_error_no_route_matches.png +0 -0
  13. data/guides/assets/images/getting_started/template_is_missing_posts_new.png +0 -0
  14. data/guides/assets/images/getting_started/unknown_action_create_for_posts.png +0 -0
  15. data/guides/assets/images/getting_started/unknown_action_new_for_posts.png +0 -0
  16. data/guides/assets/images/header_tile.gif +0 -0
  17. data/guides/assets/images/icons/README +1 -1
  18. data/guides/assets/images/icons/callouts/11.png +0 -0
  19. data/guides/assets/images/icons/callouts/12.png +0 -0
  20. data/guides/assets/images/icons/callouts/13.png +0 -0
  21. data/guides/assets/images/icons/callouts/15.png +0 -0
  22. data/guides/assets/images/icons/caution.png +0 -0
  23. data/guides/assets/images/icons/example.png +0 -0
  24. data/guides/assets/images/radar.png +0 -0
  25. data/guides/assets/images/rails4_features.png +0 -0
  26. data/guides/assets/images/rails_guides_kindle_cover.jpg +0 -0
  27. data/guides/assets/images/vijaydev.jpg +0 -0
  28. data/guides/assets/javascripts/guides.js +30 -34
  29. data/guides/assets/stylesheets/main.css +2 -1
  30. data/guides/assets/stylesheets/print.css +1 -1
  31. data/guides/bug_report_templates/action_controller_gem.rb +2 -0
  32. data/guides/bug_report_templates/action_controller_master.rb +2 -0
  33. data/guides/bug_report_templates/active_record_gem.rb +1 -1
  34. data/guides/bug_report_templates/active_record_master.rb +2 -1
  35. data/guides/code/getting_started/Gemfile +1 -1
  36. data/guides/code/getting_started/app/assets/javascripts/application.js +1 -2
  37. data/guides/code/getting_started/config/environments/development.rb +1 -1
  38. data/guides/code/getting_started/public/404.html +2 -0
  39. data/guides/code/getting_started/public/422.html +2 -0
  40. data/guides/code/getting_started/public/500.html +2 -0
  41. data/guides/rails_guides/helpers.rb +1 -1
  42. data/guides/source/2_2_release_notes.md +2 -2
  43. data/guides/source/2_3_release_notes.md +8 -8
  44. data/guides/source/3_0_release_notes.md +1 -2
  45. data/guides/source/3_1_release_notes.md +1 -1
  46. data/guides/source/3_2_release_notes.md +12 -12
  47. data/guides/source/4_0_release_notes.md +79 -46
  48. data/guides/source/4_1_release_notes.md +601 -0
  49. data/guides/source/_welcome.html.erb +1 -1
  50. data/guides/source/action_controller_overview.md +117 -31
  51. data/guides/source/action_mailer_basics.md +19 -19
  52. data/guides/source/action_view_overview.md +131 -12
  53. data/guides/source/active_model_basics.md +6 -6
  54. data/guides/source/active_record_basics.md +15 -15
  55. data/guides/source/active_record_callbacks.md +18 -16
  56. data/guides/source/active_record_querying.md +67 -39
  57. data/guides/source/active_record_validations.md +31 -31
  58. data/guides/source/active_support_core_extensions.md +63 -74
  59. data/guides/source/active_support_instrumentation.md +13 -4
  60. data/guides/source/api_documentation_guidelines.md +19 -5
  61. data/guides/source/asset_pipeline.md +544 -249
  62. data/guides/source/association_basics.md +81 -22
  63. data/guides/source/caching_with_rails.md +15 -6
  64. data/guides/source/command_line.md +28 -19
  65. data/guides/source/configuring.md +98 -50
  66. data/guides/source/contributing_to_ruby_on_rails.md +11 -11
  67. data/guides/source/credits.html.erb +2 -2
  68. data/guides/source/debugging_rails_applications.md +36 -5
  69. data/guides/source/development_dependencies_install.md +89 -8
  70. data/guides/source/documents.yaml +7 -1
  71. data/guides/source/engines.md +648 -224
  72. data/guides/source/form_helpers.md +56 -45
  73. data/guides/source/generators.md +7 -3
  74. data/guides/source/getting_started.md +379 -164
  75. data/guides/source/i18n.md +59 -23
  76. data/guides/source/index.html.erb +1 -1
  77. data/guides/source/initialization.md +153 -56
  78. data/guides/source/kindle/toc.html.erb +1 -1
  79. data/guides/source/layout.html.erb +3 -3
  80. data/guides/source/layouts_and_rendering.md +12 -11
  81. data/guides/source/maintenance_policy.md +4 -23
  82. data/guides/source/migrations.md +41 -37
  83. data/guides/source/nested_model_forms.md +3 -3
  84. data/guides/source/plugins.md +27 -23
  85. data/guides/source/rails_application_templates.md +25 -6
  86. data/guides/source/rails_on_rack.md +35 -51
  87. data/guides/source/routing.md +108 -99
  88. data/guides/source/ruby_on_rails_guides_guidelines.md +2 -2
  89. data/guides/source/security.md +33 -31
  90. data/guides/source/testing.md +37 -34
  91. data/guides/source/upgrading_ruby_on_rails.md +335 -16
  92. data/guides/source/working_with_javascript_in_rails.md +18 -10
  93. metadata +66 -39
  94. data/guides/assets/images/jaimeiniesta.jpg +0 -0
  95. data/guides/source/kindle/KINDLE.md +0 -26
@@ -30,10 +30,10 @@ Configuring Rails Components
30
30
 
31
31
  In general, the work of configuring Rails means configuring the components of Rails, as well as configuring Rails itself. The configuration file `config/application.rb` and environment-specific configuration files (such as `config/environments/production.rb`) allow you to specify the various settings that you want to pass down to all of the components.
32
32
 
33
- For example, the default `config/application.rb` file includes this setting:
33
+ For example, the `config/application.rb` file includes this setting:
34
34
 
35
35
  ```ruby
36
- config.filter_parameters += [:password]
36
+ config.autoload_paths += %W(#{config.root}/extras)
37
37
  ```
38
38
 
39
39
  This is a setting for Rails itself. If you want to pass settings to individual Rails components, you can do so via the same `config` object in `config/application.rb`:
@@ -66,6 +66,9 @@ These configuration methods are to be called on a `Rails::Railtie` object, such
66
66
 
67
67
  * `config.action_view.cache_template_loading` controls whether or not templates should be reloaded on each request. Defaults to whatever is set for `config.cache_classes`.
68
68
 
69
+ * `config.beginning_of_week` sets the default beginning of week for the
70
+ application. Accepts a valid week day symbol (e.g. `:monday`).
71
+
69
72
  * `config.cache_store` configures which cache store to use for Rails caching. Options include one of the symbols `:memory_store`, `:file_store`, `:mem_cache_store`, `:null_store`, or an object that implements the cache API. Defaults to `:file_store` if the directory `tmp/cache` exists, and to `:memory_store` otherwise.
70
73
 
71
74
  * `config.colorize_logging` specifies whether or not to use ANSI color codes when logging information. Defaults to true.
@@ -97,15 +100,17 @@ These configuration methods are to be called on a `Rails::Railtie` object, such
97
100
 
98
101
  * `config.file_watcher` the class used to detect file updates in the filesystem when `config.reload_classes_only_on_change` is true. Must conform to `ActiveSupport::FileUpdateChecker` API.
99
102
 
100
- * `config.filter_parameters` used for filtering out the parameters that you don't want shown in the logs, such as passwords or credit card numbers.
103
+ * `config.filter_parameters` used for filtering out the parameters that
104
+ you don't want shown in the logs, such as passwords or credit card
105
+ numbers. New applications filter out passwords by adding the following `config.filter_parameters+=[:password]` in `config/initializers/filter_parameter_logging.rb`.
101
106
 
102
107
  * `config.force_ssl` forces all requests to be under HTTPS protocol by using `ActionDispatch::SSL` middleware.
103
108
 
104
- * `config.log_formatter` defines the formatter of the Rails logger. This option defaults to a instance of `ActiveSupport::Logger::SimpleFormatter` for all modes except production, where it defaults to `Logger::Formatter`.
109
+ * `config.log_formatter` defines the formatter of the Rails logger. This option defaults to an instance of `ActiveSupport::Logger::SimpleFormatter` for all modes except production, where it defaults to `Logger::Formatter`.
105
110
 
106
111
  * `config.log_level` defines the verbosity of the Rails logger. This option defaults to `:debug` for all modes except production, where it defaults to `:info`.
107
112
 
108
- * `config.log_tags` accepts a list of methods that respond to `request` object. This makes it easy to tag log lines with debug information like subdomain and request id both very helpful in debugging multi-user production applications.
113
+ * `config.log_tags` accepts a list of methods that respond to `request` object. This makes it easy to tag log lines with debug information like subdomain and request id - both very helpful in debugging multi-user production applications.
109
114
 
110
115
  * `config.logger` accepts a logger conforming to the interface of Log4r or the default Ruby `Logger` class. Defaults to an instance of `ActiveSupport::Logger`, with auto flushing off in production mode.
111
116
 
@@ -115,7 +120,7 @@ These configuration methods are to be called on a `Rails::Railtie` object, such
115
120
 
116
121
  * `config.secret_key_base` used for specifying a key which allows sessions for the application to be verified against a known secure key to prevent tampering. Applications get `config.secret_key_base` initialized to a random key in `config/initializers/secret_token.rb`.
117
122
 
118
- * `config.serve_static_assets` configures Rails itself to serve static assets. Defaults to true, but in the production environment is turned off as the server software (e.g. Nginx or Apache) used to run the application should serve static assets instead. Unlike the default setting set this to true when running (absolutely not recommended!) or testing your app in production mode using WEBrick. Otherwise you won´t be able use page caching and requests for files that exist regularly under the public directory will anyway hit your Rails app.
123
+ * `config.serve_static_assets` configures Rails itself to serve static assets. Defaults to true, but in the production environment is turned off as the server software (e.g. Nginx or Apache) used to run the application should serve static assets instead. Unlike the default setting set this to true when running (absolutely not recommended!) or testing your app in production mode using WEBrick. Otherwise you won't be able use page caching and requests for files that exist regularly under the public directory will anyway hit your Rails app.
119
124
 
120
125
  * `config.session_store` is usually set up in `config/initializers/session_store.rb` and specifies what class to use to store the session. Possible values are `:cookie_store` which is the default, `:mem_cache_store`, and `:disabled`. The last one tells Rails not to deal with sessions. Custom session stores can also be specified:
121
126
 
@@ -127,13 +132,10 @@ These configuration methods are to be called on a `Rails::Railtie` object, such
127
132
 
128
133
  * `config.time_zone` sets the default time zone for the application and enables time zone awareness for Active Record.
129
134
 
130
- * `config.beginning_of_week` sets the default beginning of week for the application. Accepts a valid week day symbol (e.g. `:monday`).
131
-
132
- * `config.whiny_nils` enables or disables warnings when a certain set of methods are invoked on `nil` and it does not respond to them. Defaults to true in development and test environments.
133
-
134
135
  ### Configuring Assets
135
136
 
136
- * `config.assets.enabled` a flag that controls whether the asset pipeline is enabled. It is explicitly initialized in `config/application.rb`.
137
+ * `config.assets.enabled` a flag that controls whether the asset
138
+ pipeline is enabled. It is set to true by default.
137
139
 
138
140
  * `config.assets.compress` a flag that enables the compression of compiled assets. It is explicitly set to true in `config/production.rb`.
139
141
 
@@ -195,7 +197,7 @@ Every Rails application comes with a standard set of middleware which it uses in
195
197
  * `Rack::Lock` wraps the app in mutex so it can only be called by a single thread at a time. Only enabled when `config.cache_classes` is `false`.
196
198
  * `ActiveSupport::Cache::Strategy::LocalCache` serves as a basic memory backed cache. This cache is not thread safe and is intended only for serving as a temporary memory cache for a single thread.
197
199
  * `Rack::Runtime` sets an `X-Runtime` header, containing the time (in seconds) taken to execute the request.
198
- * `Rails::Rack::Logger` notifies the logs that the request has began. After request is complete, flushes all the logs.
200
+ * `Rails::Rack::Logger` notifies the logs that the request has begun. After request is complete, flushes all the logs.
199
201
  * `ActionDispatch::ShowExceptions` rescues any exception returned by the application and renders nice exception pages if the request is local or if `config.consider_all_requests_local` is set to `true`. If `config.action_dispatch.show_exceptions` is set to `false`, exceptions will be raised regardless.
200
202
  * `ActionDispatch::RequestId` makes a unique X-Request-Id header available to the response and enables the `ActionDispatch::Request#uuid` method.
201
203
  * `ActionDispatch::RemoteIp` checks for IP spoofing attacks and gets valid `client_ip` from request headers. Configurable with the `config.action_dispatch.ip_spoofing_check`, and `config.action_dispatch.trusted_proxies` options.
@@ -242,14 +244,8 @@ config.middleware.delete "Rack::MethodOverride"
242
244
 
243
245
  ### Configuring i18n
244
246
 
245
- All these configuration options are delegated to the `I18n` library.
246
-
247
- * `config.i18n.available_locales` whitelists the available locales for the app. Defaults to all locale keys found in locale files, usually only `:en` on a new application.
248
-
249
247
  * `config.i18n.default_locale` sets the default locale of an application used for i18n. Defaults to `:en`.
250
248
 
251
- * `config.i18n.enforce_available_locales` ensures that all locales passed through i18n must be declared in the `available_locales` list, raising an `I18n::InvalidLocale` exception when setting an unavailable locale. Defaults to `true`. It is recommended not to disable this option unless strongly required, since this works as a security measure against setting any invalid locale from user input.
252
-
253
249
  * `config.i18n.load_path` sets the path Rails uses to look for locale files. Defaults to `config/locales/*.{yml,rb}`.
254
250
 
255
251
  ### Configuring Active Record
@@ -266,6 +262,8 @@ All these configuration options are delegated to the `I18n` library.
266
262
 
267
263
  * `config.active_record.table_name_suffix` lets you set a global string to be appended to table names. If you set this to `_northwest`, then the Customer class will look for `customers_northwest` as its table. The default is an empty string.
268
264
 
265
+ * `config.active_record.schema_migrations_table_name` lets you set a string to be used as the name of the schema migrations table.
266
+
269
267
  * `config.active_record.pluralize_table_names` specifies whether Rails will look for singular or plural table names in the database. If set to true (the default), then the Customer class will use the `customers` table. If set to false, then the Customer class will use the `customer` table.
270
268
 
271
269
  * `config.active_record.default_timezone` determines whether to use `Time.local` (if set to `:local`) or `Time.utc` (if set to `:utc`) when pulling dates and times from the database. The default is `:utc` for Rails, although Active Record defaults to `:local` when used outside of Rails.
@@ -278,6 +276,12 @@ All these configuration options are delegated to the `I18n` library.
278
276
 
279
277
  * `config.active_record.cache_timestamp_format` controls the format of the timestamp value in the cache key. Default is `:number`.
280
278
 
279
+ * `config.active_record.record_timestamps` is a boolean value which controls whether or not timestamping of `create` and `update` operations on a model occur. The default value is `true`.
280
+
281
+ * `config.active_record.partial_writes` is a boolean value and controls whether or not partial writes are used (i.e. whether updates only set attributes that are dirty). Note that when using partial writes, you should also use optimistic locking `config.active_record.lock_optimistically` since concurrent updates may write attributes based on a possibly stale read state. The default value is `true`.
282
+
283
+ * `config.active_record.attribute_types_cached_by_default` sets the attribute types that `ActiveRecord::AttributeMethods` will cache by default on reads. The default is `[:datetime, :timestamp, :time, :date]`.
284
+
281
285
  The MySQL adapter adds one additional configuration option:
282
286
 
283
287
  * `ActiveRecord::ConnectionAdapters::MysqlAdapter.emulate_booleans` controls whether Active Record will consider all `tinyint(1)` columns in a MySQL database to be booleans and is true by default.
@@ -304,7 +308,7 @@ The schema dumper adds one additional configuration option:
304
308
 
305
309
  * `config.action_controller.allow_forgery_protection` enables or disables CSRF protection. By default this is `false` in test mode and `true` in all other modes.
306
310
 
307
- * `config.action_controller.relative_url_root` can be used to tell Rails that you are deploying to a subdirectory. The default is `ENV['RAILS_RELATIVE_URL_ROOT']`.
311
+ * `config.action_controller.relative_url_root` can be used to tell Rails that you are [deploying to a subdirectory](configuring.html#deploy-to-a-subdirectory-relative-url-root). The default is `ENV['RAILS_RELATIVE_URL_ROOT']`.
308
312
 
309
313
  * `config.action_controller.permit_all_parameters` sets all the parameters for mass assignment to be permitted by default. The default value is `false`.
310
314
 
@@ -326,6 +330,18 @@ The schema dumper adds one additional configuration option:
326
330
 
327
331
  * `config.action_dispatch.tld_length` sets the TLD (top-level domain) length for the application. Defaults to `1`.
328
332
 
333
+ * `config.action_dispatch.http_auth_salt` sets the HTTP Auth salt value. Defaults
334
+ to `'http authentication'`.
335
+
336
+ * `config.action_dispatch.signed_cookie_salt` sets the signed cookies salt value.
337
+ Defaults to `'signed cookie'`.
338
+
339
+ * `config.action_dispatch.encrypted_cookie_salt` sets the encrypted cookies salt
340
+ value. Defaults to `'encrypted cookie'`.
341
+
342
+ * `config.action_dispatch.encrypted_signed_cookie_salt` sets the signed
343
+ encrypted cookies salt value. Defaults to `'signed encrypted cookie'`.
344
+
329
345
  * `ActionDispatch::Callbacks.before` takes a block of code to run before the request.
330
346
 
331
347
  * `ActionDispatch::Callbacks.to_prepare` takes a block to run after `ActionDispatch::Callbacks.before`, but before the request. Runs for every request in `development` mode, but only once for `production` or environments with `cache_classes` set to `true`.
@@ -360,8 +376,6 @@ The schema dumper adds one additional configuration option:
360
376
 
361
377
  The default setting is `true`, which uses the partial at `/admin/posts/_post.erb`. Setting the value to `false` would render `/posts/_post.erb`, which is the same behavior as rendering from a non-namespaced controller such as `PostsController`.
362
378
 
363
- * `config.action_view.raise_on_missing_translations` determines whether an error should be raised for missing translations
364
-
365
379
  ### Configuring Action Mailer
366
380
 
367
381
  There are a number of settings available on `config.action_mailer`:
@@ -431,13 +445,13 @@ There are a few configuration options available in Active Support:
431
445
 
432
446
  ### Configuring a Database
433
447
 
434
- Just about every Rails application will interact with a database. The database to use is specified in a configuration file called `config/database.yml`. If you open this file in a new Rails application, you'll see a default database configured to use SQLite3. The file contains sections for three different environments in which Rails can run by default:
448
+ Just about every Rails application will interact with a database. The database to use is specified in a configuration file called `config/database.yml`. If you open this file in a new Rails application, you'll see a default database configured to use SQLite3. The file contains sections for three different environments in which Rails can run by default:
435
449
 
436
450
  * The `development` environment is used on your development/local computer as you interact manually with the application.
437
451
  * The `test` environment is used when running automated tests.
438
452
  * The `production` environment is used when you deploy your application for the world to use.
439
453
 
440
- TIP: You don't have to update the database configurations manually. If you look at the options of the application generator, you will see that one of the options is named `--database`. This option allows you to choose an adapter from a list of the most used relational databases. You can even run the generator repeatedly: `cd .. && rails new blog --database=mysql`. When you confirm the overwriting of the `config/database.yml` file, your application will be configured for MySQL instead of SQLite. Detailed examples of the common database connections are below.
454
+ TIP: You don't have to update the database configurations manually. If you look at the options of the application generator, you will see that one of the options is named `--database`. This option allows you to choose an adapter from a list of the most used relational databases. You can even run the generator repeatedly: `cd .. && rails new blog --database=mysql`. When you confirm the overwriting of the `config/database.yml` file, your application will be configured for MySQL instead of SQLite. Detailed examples of the common database connections are below.
441
455
 
442
456
  #### Configuring an SQLite3 Database
443
457
 
@@ -535,10 +549,47 @@ Change the username and password in the `development` section as appropriate.
535
549
 
536
550
  By default Rails ships with three environments: "development", "test", and "production". While these are sufficient for most use cases, there are circumstances when you want more environments.
537
551
 
538
- Imagine you have a server which mirrors the production environment but is only used for testing. Such a server is commonly called a "staging server". To define an environment called "staging" for this server just by create a file called `config/environments/staging.rb`. Please use the contents of any existing file in `config/environments` as a starting point and make the necessary changes from there.
552
+ Imagine you have a server which mirrors the production environment but is only used for testing. Such a server is commonly called a "staging server". To define an environment called "staging" for this server, just create a file called `config/environments/staging.rb`. Please use the contents of any existing file in `config/environments` as a starting point and make the necessary changes from there.
553
+
554
+ That environment is no different than the default ones, start a server with `rails server -e staging`, a console with `rails console staging`, `Rails.env.staging?` works, etc.
555
+
539
556
 
540
- That environment is no different than the default ones, start a server with `rails server -e staging`, a console with `rails console staging`, `Rails.env.staging?` works, etc.
557
+ ### Deploy to a subdirectory (relative url root)
558
+
559
+ By default Rails expects that your application is running at the root
560
+ (eg. `/`). This section explains how to run your application inside a directory.
561
+
562
+ Let's assume we want to deploy our application to "/app1". Rails needs to know
563
+ this directory to generate the appropriate routes:
564
+
565
+ ```ruby
566
+ config.relative_url_root = "/app1"
567
+ ```
541
568
 
569
+ alternatively you can set the `RAILS_RELATIVE_URL_ROOT` environment
570
+ variable.
571
+
572
+ Rails will now prepend "/app1" when generating links.
573
+
574
+ #### Using Passenger
575
+
576
+ Passenger makes it easiy to run your application in a subdirectory. You can find
577
+ the relevant configuration in the
578
+ [passenger manual](http://www.modrails.com/documentation/Users%20guide%20Apache.html#deploying_rails_to_sub_uri).
579
+
580
+ #### Using a Reverse Proxy
581
+
582
+ TODO
583
+
584
+ #### Considerations when deploying to a subdirectory
585
+
586
+ Deploying to a subdirectory in production has implications on various parts of
587
+ Rails.
588
+
589
+ * development environment:
590
+ * testing environment:
591
+ * serving static assets:
592
+ * asset pipeline:
542
593
 
543
594
  Rails Environment Settings
544
595
  --------------------------
@@ -547,7 +598,7 @@ Some parts of Rails can also be configured externally by supplying environment v
547
598
 
548
599
  * `ENV["RAILS_ENV"]` defines the Rails environment (production, development, test, and so on) that Rails will run under.
549
600
 
550
- * `ENV["RAILS_RELATIVE_URL_ROOT"]` is used by the routing code to recognize URLs when you deploy your application to a subdirectory.
601
+ * `ENV["RAILS_RELATIVE_URL_ROOT"]` is used by the routing code to recognize URLs when you [deploy your application to a subdirectory](configuring.html#deploy-to-a-subdirectory-relative-url-root).
551
602
 
552
603
  * `ENV["RAILS_CACHE_ID"]` and `ENV["RAILS_APP_VERSION"]` are used to generate expanded cache keys in Rails' caching code. This allows you to have multiple separate caches from the same application.
553
604
 
@@ -600,17 +651,17 @@ WARNING: Some parts of your application, notably routing, are not yet set up at
600
651
 
601
652
  ### `Rails::Railtie#initializer`
602
653
 
603
- Rails has several initializers that run on startup that are all defined by using the `initializer` method from `Rails::Railtie`. Here's an example of the `initialize_whiny_nils` initializer from Active Support:
654
+ Rails has several initializers that run on startup that are all defined by using the `initializer` method from `Rails::Railtie`. Here's an example of the `set_helpers_path` initializer from Action Controller:
604
655
 
605
656
  ```ruby
606
- initializer "active_support.initialize_whiny_nils" do |app|
607
- require 'active_support/whiny_nil' if app.config.whiny_nils
657
+ initializer "action_controller.set_helpers_path" do |app|
658
+ ActionController::Helpers.helpers_path = app.helpers_paths
608
659
  end
609
660
  ```
610
661
 
611
662
  The `initializer` method takes three arguments with the first being the name for the initializer and the second being an options hash (not shown here) and the third being a block. The `:before` key in the options hash can be specified to specify which initializer this new initializer must run before, and the `:after` key will specify which initializer to run this initializer _after_.
612
663
 
613
- Initializers defined using the `initializer` method will be ran in the order they are defined in, with the exception of ones that use the `:before` or `:after` methods.
664
+ Initializers defined using the `initializer` method will be run in the order they are defined in, with the exception of ones that use the `:before` or `:after` methods.
614
665
 
615
666
  WARNING: You may put your initializer before or after any other initializer in the chain, as long as it is logical. Say you have 4 initializers called "one" through "four" (defined in that order) and you define "four" to go _before_ "four" but _after_ "three", that just isn't logical and Rails will not be able to determine your initializer order.
616
667
 
@@ -630,7 +681,7 @@ Below is a comprehensive list of all the initializers found in Rails in the orde
630
681
 
631
682
  * `initialize_cache` If `Rails.cache` isn't set yet, initializes the cache by referencing the value in `config.cache_store` and stores the outcome as `Rails.cache`. If this object responds to the `middleware` method, its middleware is inserted before `Rack::Runtime` in the middleware stack.
632
683
 
633
- * `set_clear_dependencies_hook` Provides a hook for `active_record.set_dispatch_hooks` to use, which will run before this initializer. This initializer which runs only if `cache_classes` is set to `false` uses `ActionDispatch::Callbacks.after` to remove the constants which have been referenced during the request from the object space so that they will be reloaded during the following request.
684
+ * `set_clear_dependencies_hook` Provides a hook for `active_record.set_dispatch_hooks` to use, which will run before this initializer. This initializer - which runs only if `cache_classes` is set to `false` - uses `ActionDispatch::Callbacks.after` to remove the constants which have been referenced during the request from the object space so that they will be reloaded during the following request.
634
685
 
635
686
  * `initialize_dependency_mechanism` If `config.cache_classes` is true, configures `ActiveSupport::Dependencies.mechanism` to `require` dependencies rather than `load` them.
636
687
 
@@ -638,20 +689,6 @@ Below is a comprehensive list of all the initializers found in Rails in the orde
638
689
 
639
690
  * `i18n.callbacks` In the development environment, sets up a `to_prepare` callback which will call `I18n.reload!` if any of the locales have changed since the last request. In production mode this callback will only run on the first request.
640
691
 
641
- * `active_support.initialize_whiny_nils` Requires `active_support/whiny_nil` if `config.whiny_nils` is true. This file will output errors such as:
642
-
643
- ```
644
- Called id for nil, which would mistakenly be 4 — if you really wanted the id of nil, use object_id
645
- ```
646
-
647
- And:
648
-
649
- ```
650
- You have a nil object when you didn't expect it!
651
- You might have expected an instance of Array.
652
- The error occurred while evaluating nil.each
653
- ```
654
-
655
692
  * `active_support.deprecation_behavior` Sets up deprecation reporting for environments, defaulting to `:log` for development, `:notify` for production and `:stderr` for test. If a value isn't set for `config.active_support.deprecation` then this initializer will prompt the user to configure this line in the current environment's `config/environments` file. Can be set to an array of values.
656
693
 
657
694
  * `active_support.initialize_time_zone` Sets the default time zone for the application based on the `config.time_zone` setting, which defaults to "UTC".
@@ -662,9 +699,9 @@ Below is a comprehensive list of all the initializers found in Rails in the orde
662
699
 
663
700
  * `action_view.set_configs` Sets up Action View by using the settings in `config.action_view` by `send`'ing the method names as setters to `ActionView::Base` and passing the values through.
664
701
 
665
- * `action_controller.logger` Sets `ActionController::Base.logger` if it's not already set to `Rails.logger`.
702
+ * `action_controller.logger` Sets `ActionController::Base.logger` - if it's not already set - to `Rails.logger`.
666
703
 
667
- * `action_controller.initialize_framework_caches` Sets `ActionController::Base.cache_store` if it's not already set to `Rails.cache`.
704
+ * `action_controller.initialize_framework_caches` Sets `ActionController::Base.cache_store` - if it's not already set - to `Rails.cache`.
668
705
 
669
706
  * `action_controller.set_configs` Sets up Action Controller by using the settings in `config.action_controller` by `send`'ing the method names as setters to `ActionController::Base` and passing the values through.
670
707
 
@@ -672,7 +709,7 @@ Below is a comprehensive list of all the initializers found in Rails in the orde
672
709
 
673
710
  * `active_record.initialize_timezone` Sets `ActiveRecord::Base.time_zone_aware_attributes` to true, as well as setting `ActiveRecord::Base.default_timezone` to UTC. When attributes are read from the database, they will be converted into the time zone specified by `Time.zone`.
674
711
 
675
- * `active_record.logger` Sets `ActiveRecord::Base.logger` if it's not already set to `Rails.logger`.
712
+ * `active_record.logger` Sets `ActiveRecord::Base.logger` - if it's not already set - to `Rails.logger`.
676
713
 
677
714
  * `active_record.set_configs` Sets up Active Record by using the settings in `config.active_record` by `send`'ing the method names as setters to `ActiveRecord::Base` and passing the values through.
678
715
 
@@ -682,7 +719,7 @@ Below is a comprehensive list of all the initializers found in Rails in the orde
682
719
 
683
720
  * `active_record.set_dispatch_hooks` Resets all reloadable connections to the database if `config.cache_classes` is set to `false`.
684
721
 
685
- * `action_mailer.logger` Sets `ActionMailer::Base.logger` if it's not already set to `Rails.logger`.
722
+ * `action_mailer.logger` Sets `ActionMailer::Base.logger` - if it's not already set - to `Rails.logger`.
686
723
 
687
724
  * `action_mailer.set_configs` Sets up Action Mailer by using the settings in `config.action_mailer` by `send`'ing the method names as setters to `ActionMailer::Base` and passing the values through.
688
725
 
@@ -712,7 +749,7 @@ Below is a comprehensive list of all the initializers found in Rails in the orde
712
749
 
713
750
  * `ensure_autoload_once_paths_as_subset` Ensures that the `config.autoload_once_paths` only contains paths from `config.autoload_paths`. If it contains extra paths, then an exception will be raised.
714
751
 
715
- * `add_to_prepare_blocks` The block for every `config.to_prepare` call in the application, a railtie or engine is added to the `to_prepare` callbacks for Action Dispatch which will be ran per request in development, or before the first request in production.
752
+ * `add_to_prepare_blocks` The block for every `config.to_prepare` call in the application, a railtie or engine is added to the `to_prepare` callbacks for Action Dispatch which will be run per request in development, or before the first request in production.
716
753
 
717
754
  * `add_builtin_route` If the application is running under the development environment then this will append the route for `rails/info/properties` to the application routes. This route provides the detailed information such as Rails and Ruby version for `public/index.html` in a default Rails application.
718
755
 
@@ -743,4 +780,15 @@ Since the connection pooling is handled inside of Active Record by default, all
743
780
 
744
781
  Any one request will check out a connection the first time it requires access to the database, after which it will check the connection back in, at the end of the request, meaning that the additional connection slot will be available again for the next request in the queue.
745
782
 
783
+ If you try to use more connections than are available, Active Record will block
784
+ and wait for a connection from the pool. When it cannot get connection, a timeout
785
+ error similar to given below will be thrown.
786
+
787
+ ```ruby
788
+ ActiveRecord::ConnectionTimeoutError - could not obtain a database connection within 5 seconds. The max pool size is currently 5; consider increasing it:
789
+ ```
790
+
791
+ If you get the above error, you might want to increase the size of connection
792
+ pool by incrementing the `pool` option in `database.yml`
793
+
746
794
  NOTE. If you have enabled `Rails.threadsafe!` mode then there could be a chance that several threads may be accessing multiple connections simultaneously. So depending on your current request load, you could very well have multiple threads contending for a limited amount of connections.
@@ -11,7 +11,7 @@ After reading this guide, you will know:
11
11
  * How to contribute to the Ruby on Rails documentation.
12
12
  * How to contribute to the Ruby on Rails code.
13
13
 
14
- Ruby on Rails is not "someone else's framework." Over the years, hundreds of people have contributed to Ruby on Rails ranging from a single character to massive architectural changes or significant documentation all with the goal of making Ruby on Rails better for everyone. Even if you don't feel up to writing code or documentation yet, there are a variety of other ways that you can contribute, from reporting issues to testing patches.
14
+ Ruby on Rails is not "someone else's framework." Over the years, hundreds of people have contributed to Ruby on Rails ranging from a single character to massive architectural changes or significant documentation - all with the goal of making Ruby on Rails better for everyone. Even if you don't feel up to writing code or documentation yet, there are a variety of other ways that you can contribute, from reporting issues to testing patches.
15
15
 
16
16
  --------------------------------------------------------------------------------
17
17
 
@@ -26,7 +26,7 @@ NOTE: Bugs in the most recent released version of Ruby on Rails are likely to ge
26
26
 
27
27
  If you've found a problem in Ruby on Rails which is not a security risk, do a search in GitHub under [Issues](https://github.com/rails/rails/issues) in case it was already reported. If you find no issue addressing it you can [add a new one](https://github.com/rails/rails/issues/new). (See the next section for reporting security issues.)
28
28
 
29
- At the minimum, your issue report needs a title and descriptive text. But that's only a minimum. You should include as much relevant information as possible. You need at least to post the code sample that has the issue. Even better is to include a unit test that shows how the expected behavior is not occurring. Your goal should be to make it easy for yourself and others to replicate the bug and figure out a fix.
29
+ At the minimum, your issue report needs a title and descriptive text. But that's only a minimum. You should include as much relevant information as possible. You need at least to post the code sample that has the issue. Even better is to include a unit test that shows how the expected behavior is not occurring. Your goal should be to make it easy for yourself - and others - to replicate the bug and figure out a fix.
30
30
 
31
31
  Then, don't get your hopes up! Unless you have a "Code Red, Mission Critical, the World is Coming to an End" kind of bug, you're creating this issue report in the hope that others with the same problem will be able to collaborate with you on solving it. Do not expect that the issue report will automatically see any activity or that others will jump to fix it. Creating an issue like this is mostly to help yourself start on the path of fixing the problem and for others to confirm it with an "I'm having this problem too" comment.
32
32
 
@@ -55,7 +55,7 @@ can expect it to be marked "invalid" as soon as it's reviewed.
55
55
 
56
56
  Sometimes, the line between 'bug' and 'feature' is a hard one to draw.
57
57
  Generally, a feature is anything that adds new behavior, while a bug is
58
- anything that fixes already existing behavior that is mis-behaving. Sometimes,
58
+ anything that fixes already existing behavior that is misbehaving. Sometimes,
59
59
  the core team will have to make a judgement call. That said, the distinction
60
60
  generally just affects which release your patch will get in to; we love feature
61
61
  submissions! They just won't get backported to maintenance branches.
@@ -193,7 +193,7 @@ After applying their branch, test it out! Here are some things to think about:
193
193
  Once you're happy that the pull request contains a good change, comment on the GitHub issue indicating your approval. Your comment should indicate that you like the change and what you like about it. Something like:
194
194
 
195
195
  <blockquote>
196
- I like the way you've restructured that code in generate_finder_sql much nicer. The tests look good too.
196
+ I like the way you've restructured that code in generate_finder_sql - much nicer. The tests look good too.
197
197
  </blockquote>
198
198
 
199
199
  If your comment simply says "+1", then odds are that other reviewers aren't going to take it too seriously. Show that you took the time to review the pull request.
@@ -219,7 +219,7 @@ When working with documentation, please take into account the [API Documentation
219
219
 
220
220
  NOTE: As explained earlier, ordinary code patches should have proper documentation coverage. Docrails is only used for isolated documentation improvements.
221
221
 
222
- NOTE: To help our CI servers you can add [ci skip] to your documentation commit message to skip build on that commit. Please remember to use it for commits containing only documentation changes.
222
+ NOTE: To help our CI servers you should add [ci skip] to your documentation commit message to skip build on that commit. Please remember to use it for commits containing only documentation changes.
223
223
 
224
224
  WARNING: Docrails has a very strict policy: no code can be touched whatsoever, no matter how trivial or small the change. Only RDoc and guides can be edited via docrails. Also, CHANGELOGs should never be edited in docrails.
225
225
 
@@ -241,11 +241,11 @@ $ cd rails
241
241
  $ git checkout -b my_new_branch
242
242
  ```
243
243
 
244
- It doesnt matter much what name you use, because this branch will only exist on your local computer and your personal repository on GitHub. It won't be part of the Rails Git repository.
244
+ It doesn't matter much what name you use, because this branch will only exist on your local computer and your personal repository on GitHub. It won't be part of the Rails Git repository.
245
245
 
246
246
  ### Write Your Code
247
247
 
248
- Now get busy and add or edit code. Youre on your branch now, so you can write whatever you want (you can check to make sure youre on the right branch with `git branch -a`). But if youre planning to submit your change back for inclusion in Rails, keep a few things in mind:
248
+ Now get busy and add or edit code. You're on your branch now, so you can write whatever you want (you can check to make sure you're on the right branch with `git branch -a`). But if you're planning to submit your change back for inclusion in Rails, keep a few things in mind:
249
249
 
250
250
  * Get the code right.
251
251
  * Use Rails idioms and helpers.
@@ -281,7 +281,7 @@ Rails follows a simple set of coding style conventions:
281
281
  * Prefer `method { do_stuff }` instead of `method{do_stuff}` for single-line blocks.
282
282
  * Follow the conventions in the source you see used already.
283
283
 
284
- The above are guidelines please use your best judgment in using them.
284
+ The above are guidelines - please use your best judgment in using them.
285
285
 
286
286
  ### Updating the CHANGELOG
287
287
 
@@ -289,7 +289,7 @@ The CHANGELOG is an important part of every release. It keeps the list of change
289
289
 
290
290
  You should add an entry to the CHANGELOG of the framework that you modified if you're adding or removing a feature, committing a bug fix or adding deprecation notices. Refactorings and documentation changes generally should not go to the CHANGELOG.
291
291
 
292
- A CHANGELOG entry should summarize what was changed and should end with author's name. You can use multiple lines if you need more space and you can attach code examples indented with 4 spaces. If a change is related to a specific issue, you should attach issue's number. Here is an example CHANGELOG entry:
292
+ A CHANGELOG entry should summarize what was changed and should end with author's name and it should go on top of a CHANGELOG. You can use multiple lines if you need more space and you can attach code examples indented with 4 spaces. If a change is related to a specific issue, you should attach issue's number. Here is an example CHANGELOG entry:
293
293
 
294
294
  ```
295
295
  * Summary of a change that briefly describes what was changed. You can use multiple
@@ -360,7 +360,7 @@ TIP. Please squash your commits into a single commit when appropriate. This simp
360
360
 
361
361
  ### Update Your Branch
362
362
 
363
- Its pretty likely that other changes to master have happened while you were working. Go get them:
363
+ It's pretty likely that other changes to master have happened while you were working. Go get them:
364
364
 
365
365
  ```bash
366
366
  $ git checkout master
@@ -466,7 +466,7 @@ the same way that you appreciate feedback on your patches.
466
466
 
467
467
  ### Iterate as Necessary
468
468
 
469
- Its entirely possible that the feedback you get will suggest changes. Dont get discouraged: the whole point of contributing to an active open source project is to tap into community knowledge. If people are encouraging you to tweak your code, then its worth making the tweaks and resubmitting. If the feedback is that your code doesnt belong in the core, you might still think about releasing it as a gem.
469
+ It's entirely possible that the feedback you get will suggest changes. Don't get discouraged: the whole point of contributing to an active open source project is to tap into community knowledge. If people are encouraging you to tweak your code, then it's worth making the tweaks and resubmitting. If the feedback is that your code doesn't belong in the core, you might still think about releasing it as a gem.
470
470
 
471
471
  #### Squashing commits
472
472
 
@@ -40,7 +40,7 @@ Oscar Del Ben is a software engineer at <a href="http://www.wildfireapp.com/">Wi
40
40
  <% end %>
41
41
 
42
42
  <%= author('Tore Darell', 'toretore') do %>
43
- Tore Darell is an independent developer based in Menton, France who specialises in cruft-free web applications using Ruby, Rails and unobtrusive JavaScript. His home on the internet is his blog <a href="http://tore.darell.no">Sneaky Abstractions</a>.
43
+ Tore Darell is an independent developer based in Menton, France who specialises in cruft-free web applications using Ruby, Rails and unobtrusive JavaScript. His home on the Internet is his blog <a href="http://tore.darell.no">Sneaky Abstractions</a>.
44
44
  <% end %>
45
45
 
46
46
  <%= author('Jeff Dean', 'zilkey') do %>
@@ -76,5 +76,5 @@ Oscar Del Ben is a software engineer at <a href="http://www.wildfireapp.com/">Wi
76
76
  <% end %>
77
77
 
78
78
  <%= author('Akshay Surve', 'startupjockey', 'akshaysurve.jpg') do %>
79
- Akshay Surve is the Founder at <a href="http://www.deltax.com">DeltaX</a>, hackathon specialist, a midnight code junkie and ocassionally writes prose. You can connect with him on <a href="https://twitter.com/akshaysurve">Twitter</a>, <a href="http://www.linkedin.com/in/akshaysurve">Linkedin</a>, <a href="http://www.akshaysurve.com/">Personal Blog</a> or <a href="http://www.quora.com/Akshay-Surve">Quora</a>.
79
+ Akshay Surve is the Founder at <a href="http://www.deltax.com">DeltaX</a>, hackathon specialist, a midnight code junkie and occasionally writes prose. You can connect with him on <a href="https://twitter.com/akshaysurve">Twitter</a>, <a href="http://www.linkedin.com/in/akshaysurve">Linkedin</a>, <a href="http://www.akshaysurve.com/">Personal Blog</a> or <a href="http://www.quora.com/Akshay-Surve">Quora</a>.
80
80
  <% end %>
@@ -198,7 +198,7 @@ Adding extra logging like this makes it easy to search for unexpected or unusual
198
198
 
199
199
  ### Tagged Logging
200
200
 
201
- When running multi-user, multi-account applications, its often useful
201
+ When running multi-user, multi-account applications, it's often useful
202
202
  to be able to filter the logs using some custom rules. `TaggedLogging`
203
203
  in Active Support helps in doing exactly that by stamping log lines with subdomains, request ids, and anything else to aid debugging such applications.
204
204
 
@@ -209,6 +209,37 @@ logger.tagged("BCX", "Jason") { logger.info "Stuff" } # Logs "
209
209
  logger.tagged("BCX") { logger.tagged("Jason") { logger.info "Stuff" } } # Logs "[BCX] [Jason] Stuff"
210
210
  ```
211
211
 
212
+ ### Impact of Logs on Performance
213
+ Logging will always have a small impact on performance of your rails app,
214
+ particularly when logging to disk.However, there are a few subtleties:
215
+
216
+ Using the `:debug` level will have a greater performance penalty than `:fatal`,
217
+ as a far greater number of strings are being evaluated and written to the
218
+ log output (e.g. disk).
219
+
220
+ Another potential pitfall is that if you have many calls to `Logger` like this
221
+ in your code:
222
+
223
+ ```ruby
224
+ logger.debug "Person attributes hash: #{@person.attributes.inspect}"
225
+ ```
226
+
227
+ In the above example, There will be a performance impact even if the allowed
228
+ output level doesn't include debug. The reason is that Ruby has to evaluate
229
+ these strings, which includes instantiating the somewhat heavy `String` object
230
+ and interpolating the variables, and which takes time.
231
+ Therefore, it's recommended to pass blocks to the logger methods, as these are
232
+ only evaluated if the output level is the same or included in the allowed level
233
+ (i.e. lazy loading). The same code rewritten would be:
234
+
235
+ ```ruby
236
+ logger.debug {"Person attributes hash: #{@person.attributes.inspect}"}
237
+ ```
238
+
239
+ The contents of the block, and therefore the string interpolation, is only
240
+ evaluated if debug is enabled. This performance savings is only really
241
+ noticeable with large amounts of logging, but it's a good practice to employ.
242
+
212
243
  Debugging with the `debugger` gem
213
244
  ---------------------------------
214
245
 
@@ -301,7 +332,7 @@ This command shows you where you are in the code by printing 10 lines centered a
301
332
  7
302
333
  8 respond_to do |format|
303
334
  9 format.html # index.html.erb
304
- 10 format.json { render :json => @posts }
335
+ 10 format.json { render json: @posts }
305
336
  ```
306
337
 
307
338
  If you repeat the `list` command, this time using just `l`, the next ten lines of the file will be printed out.
@@ -337,7 +368,7 @@ On the other hand, to see the previous ten lines you should type `list-` (or `l-
337
368
  7
338
369
  8 respond_to do |format|
339
370
  9 format.html # index.html.erb
340
- 10 format.json { render :json => @posts }
371
+ 10 format.json { render json: @posts }
341
372
  ```
342
373
 
343
374
  This way you can move inside the file, being able to see the code above and over the line you added the `debugger`.
@@ -355,7 +386,7 @@ Finally, to see where you are in the code again you can type `list=`
355
386
  7
356
387
  8 respond_to do |format|
357
388
  9 format.html # index.html.erb
358
- 10 format.json { render :json => @posts }
389
+ 10 format.json { render json: @posts }
359
390
  ```
360
391
 
361
392
  ### The Context
@@ -648,7 +679,7 @@ In this section, you will learn how to find and fix such leaks by using tool suc
648
679
 
649
680
  [Valgrind](http://valgrind.org/) is a Linux-only application for detecting C-based memory leaks and race conditions.
650
681
 
651
- There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. For example, a C extension in the interpreter calls `malloc()` but is doesn't properly call `free()`, this memory won't be available until the app terminates.
682
+ There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. For example, if a C extension in the interpreter calls `malloc()` but doesn't properly call `free()`, this memory won't be available until the app terminates.
652
683
 
653
684
  For further information on how to install Valgrind and use with Ruby, refer to [Valgrind and Ruby](http://blog.evanweaver.com/articles/2008/02/05/valgrind-and-ruby/) by Evan Weaver.
654
685