diff --git a/guides/source/4_0_release_notes.md b/guides/source/4_0_release_notes.md index 7782cba28f..1caf066a10 100644 --- a/guides/source/4_0_release_notes.md +++ b/guides/source/4_0_release_notes.md @@ -184,15 +184,15 @@ Please refer to the [Changelog](https://github.com/rails/rails/blob/4-0-stable/a * `String#to_date` now raises `ArgumentError: invalid date` instead of `NoMethodError: undefined method 'div' for nil:NilClass` when given an invalid date. It is now the same as `Date.parse`, and it accepts more invalid dates than 3.x, such as: - ```ruby - # ActiveSupport 3.x - "asdf".to_date # => NoMethodError: undefined method `div' for nil:NilClass - "333".to_date # => NoMethodError: undefined method `div' for nil:NilClass + ```ruby + # ActiveSupport 3.x + "asdf".to_date # => NoMethodError: undefined method `div' for nil:NilClass + "333".to_date # => NoMethodError: undefined method `div' for nil:NilClass - # ActiveSupport 4 - "asdf".to_date # => ArgumentError: invalid date - "333".to_date # => Fri, 29 Nov 2013 - ``` + # ActiveSupport 4 + "asdf".to_date # => ArgumentError: invalid date + "333".to_date # => Fri, 29 Nov 2013 + ``` ### Deprecations diff --git a/guides/source/4_2_release_notes.md b/guides/source/4_2_release_notes.md index f74db334e1..80f68f249e 100644 --- a/guides/source/4_2_release_notes.md +++ b/guides/source/4_2_release_notes.md @@ -109,17 +109,17 @@ Caching is not used in the following scenarios: - The model uses single table inheritance - `find` with a list of ids, e.g.: - ```ruby - # not cached - Post.find(1, 2, 3) - Post.find([1,2]) - ``` + ```ruby + # not cached + Post.find(1, 2, 3) + Post.find([1,2]) + ``` - `find_by` with SQL fragments: - ```ruby - Post.find_by('published_at < ?', 2.weeks.ago) - ``` + ```ruby + Post.find_by('published_at < ?', 2.weeks.ago) + ``` ### Web Console diff --git a/guides/source/6_1_release_notes.md b/guides/source/6_1_release_notes.md index ed648d369c..79a16a896a 100644 --- a/guides/source/6_1_release_notes.md +++ b/guides/source/6_1_release_notes.md @@ -279,20 +279,20 @@ Please refer to the [Changelog][active-record] for detailed changes. * `where.not` now generates NAND predicates instead of NOR. - Before: + Before: - User.where.not(name: "Jon", role: "admin") - # SELECT * FROM users WHERE name != 'Jon' AND role != 'admin' + User.where.not(name: "Jon", role: "admin") + # SELECT * FROM users WHERE name != 'Jon' AND role != 'admin' - After: + After: - User.where.not(name: "Jon", role: "admin") - # SELECT * FROM users WHERE NOT (name == 'Jon' AND role == 'admin') + User.where.not(name: "Jon", role: "admin") + # SELECT * FROM users WHERE NOT (name == 'Jon' AND role == 'admin') -* To use the new per-database connection handling applications must change - `legacy_connection_handling` to false and remove deprecated accessors on - `connection_handlers`. Public methods for `connects_to` and `connected_to` - require no changes. +* To use the new per-database connection handling applications must change + `legacy_connection_handling` to false and remove deprecated accessors on + `connection_handlers`. Public methods for `connects_to` and `connected_to` + require no changes. Active Storage -------------- diff --git a/guides/source/asset_pipeline.md b/guides/source/asset_pipeline.md index 688d83b398..4afae39f30 100644 --- a/guides/source/asset_pipeline.md +++ b/guides/source/asset_pipeline.md @@ -789,23 +789,23 @@ $ RAILS_ENV=production rails assets:precompile Note the following caveats: -* If precompiled assets are available, they will be served — even if they no - longer match the original (uncompiled) assets, _even on the development - server._ +* If precompiled assets are available, they will be served — even if they no + longer match the original (uncompiled) assets, _even on the development + server._ - To ensure that the development server always compiles assets on-the-fly (and - thus always reflects the most recent state of the code), the development - environment _must be configured to keep precompiled assets in a different - location than production does._ Otherwise, any assets precompiled for use in - production will clobber requests for them in development (_i.e.,_ subsequent - changes you make to assets will not be reflected in the browser). + To ensure that the development server always compiles assets on-the-fly (and + thus always reflects the most recent state of the code), the development + environment _must be configured to keep precompiled assets in a different + location than production does._ Otherwise, any assets precompiled for use in + production will clobber requests for them in development (_i.e.,_ subsequent + changes you make to assets will not be reflected in the browser). - You can do this by adding the following line to - `config/environments/development.rb`: + You can do this by adding the following line to + `config/environments/development.rb`: - ```ruby - config.assets.prefix = "/dev-assets" - ``` + ```ruby + config.assets.prefix = "/dev-assets" + ``` * The asset precompile task in your deployment tool (_e.g.,_ Capistrano) should be disabled. * Any necessary compressors or minifiers must be available on your development diff --git a/guides/source/configuring.md b/guides/source/configuring.md index 5666dc0d65..3560eec02a 100644 --- a/guides/source/configuring.md +++ b/guides/source/configuring.md @@ -232,47 +232,47 @@ The full set of methods that can be used in this block are as follows: Every Rails application comes with a standard set of middleware which it uses in this order in the development environment: -* `ActionDispatch::HostAuthorization` prevents against DNS rebinding and other `Host` header attacks. - It is included in the development environment by default with the following configuration: +* `ActionDispatch::HostAuthorization` prevents against DNS rebinding and other `Host` header attacks. + It is included in the development environment by default with the following configuration: - ```ruby - Rails.application.config.hosts = [ - IPAddr.new("0.0.0.0/0"), # All IPv4 addresses. - IPAddr.new("::/0"), # All IPv6 addresses. - "localhost" # The localhost reserved domain. - ] - ``` + ```ruby + Rails.application.config.hosts = [ + IPAddr.new("0.0.0.0/0"), # All IPv4 addresses. + IPAddr.new("::/0"), # All IPv6 addresses. + "localhost" # The localhost reserved domain. + ] + ``` - In other environments `Rails.application.config.hosts` is empty and no - `Host` header checks will be done. If you want to guard against header - attacks on production, you have to manually permit the allowed hosts - with: + In other environments `Rails.application.config.hosts` is empty and no + `Host` header checks will be done. If you want to guard against header + attacks on production, you have to manually permit the allowed hosts + with: - ```ruby - Rails.application.config.hosts << "product.com" - ``` + ```ruby + Rails.application.config.hosts << "product.com" + ``` - The host of a request is checked against the `hosts` entries with the case - operator (`#===`), which lets `hosts` support entries of type `Regexp`, - `Proc` and `IPAddr` to name a few. Here is an example with a regexp. + The host of a request is checked against the `hosts` entries with the case + operator (`#===`), which lets `hosts` support entries of type `Regexp`, + `Proc` and `IPAddr` to name a few. Here is an example with a regexp. - ```ruby - # Allow requests from subdomains like `www.product.com` and - # `beta1.product.com`. - Rails.application.config.hosts << /.*\.product\.com/ - ``` + ```ruby + # Allow requests from subdomains like `www.product.com` and + # `beta1.product.com`. + Rails.application.config.hosts << /.*\.product\.com/ + ``` - The provided regexp will be wrapped with both anchors (`\A` and `\z`) so it - must match the entire hostname. `/product.com/`, for example, once anchored, - would fail to match `www.product.com`. + The provided regexp will be wrapped with both anchors (`\A` and `\z`) so it + must match the entire hostname. `/product.com/`, for example, once anchored, + would fail to match `www.product.com`. - A special case is supported that allows you to permit all sub-domains: + A special case is supported that allows you to permit all sub-domains: - ```ruby - # Allow requests from subdomains like `www.product.com` and - # `beta1.product.com`. - Rails.application.config.hosts << ".product.com" - ``` + ```ruby + # Allow requests from subdomains like `www.product.com` and + # `beta1.product.com`. + Rails.application.config.hosts << ".product.com" + ``` * `ActionDispatch::SSL` forces every request to be served using HTTPS. Enabled if `config.force_ssl` is set to `true`. Options passed to this can be configured by setting `config.ssl_options`. * `ActionDispatch::Static` is used to serve static assets. Disabled if `config.public_file_server.enabled` is `false`. Set `config.public_file_server.index_name` if you need to serve a static directory index file that is not named `index`. For example, to serve `main.html` instead of `index.html` for directory requests, set `config.public_file_server.index_name` to `"main"`. @@ -471,8 +471,8 @@ in controllers and views. This defaults to `false`. when traversing `belongs_to` to `has_many` associations. * `config.active_record.legacy_connection_handling` allows to enable new connection - handling API. For applications using multiple databases, this new API provides - support for granular connection swapping. + handling API. For applications using multiple databases, this new API provides + support for granular connection swapping. * `config.active_record.destroy_association_async_job` allows specifying the job that will be used to destroy the associated records in background. It defaults to `ActiveRecord::DestroyAssociationAsyncJob`. @@ -613,29 +613,46 @@ Defaults to `'signed cookie'`. * `config.action_dispatch.rescue_responses` configures what exceptions are assigned to an HTTP status. It accepts a hash and you can specify pairs of exception/status. By default, this is defined as: - ```ruby - config.action_dispatch.rescue_responses = { - 'ActionController::RoutingError' => :not_found, - 'AbstractController::ActionNotFound' => :not_found, - 'ActionController::MethodNotAllowed' => :method_not_allowed, - 'ActionController::UnknownHttpMethod' => :method_not_allowed, - 'ActionController::NotImplemented' => :not_implemented, - 'ActionController::UnknownFormat' => :not_acceptable, - 'ActionController::InvalidAuthenticityToken' => :unprocessable_entity, - 'ActionController::InvalidCrossOriginRequest' => :unprocessable_entity, - 'ActionDispatch::Http::Parameters::ParseError' => :bad_request, - 'ActionController::BadRequest' => :bad_request, - 'ActionController::ParameterMissing' => :bad_request, - 'Rack::QueryParser::ParameterTypeError' => :bad_request, - 'Rack::QueryParser::InvalidParameterError' => :bad_request, - 'ActiveRecord::RecordNotFound' => :not_found, - 'ActiveRecord::StaleObjectError' => :conflict, - 'ActiveRecord::RecordInvalid' => :unprocessable_entity, - 'ActiveRecord::RecordNotSaved' => :unprocessable_entity - } - ``` + ```ruby + config.action_dispatch.rescue_responses = { + 'ActionController::RoutingError' + => :not_found, + 'AbstractController::ActionNotFound' + => :not_found, + 'ActionController::MethodNotAllowed' + => :method_not_allowed, + 'ActionController::UnknownHttpMethod' + => :method_not_allowed, + 'ActionController::NotImplemented' + => :not_implemented, + 'ActionController::UnknownFormat' + => :not_acceptable, + 'ActionController::InvalidAuthenticityToken' + => :unprocessable_entity, + 'ActionController::InvalidCrossOriginRequest' + => :unprocessable_entity, + 'ActionDispatch::Http::Parameters::ParseError' + => :bad_request, + 'ActionController::BadRequest' + => :bad_request, + 'ActionController::ParameterMissing' + => :bad_request, + 'Rack::QueryParser::ParameterTypeError' + => :bad_request, + 'Rack::QueryParser::InvalidParameterError' + => :bad_request, + 'ActiveRecord::RecordNotFound' + => :not_found, + 'ActiveRecord::StaleObjectError' + => :conflict, + 'ActiveRecord::RecordInvalid' + => :unprocessable_entity, + 'ActiveRecord::RecordNotSaved' + => :unprocessable_entity + } + ``` - Any exceptions that are not configured will be mapped to 500 Internal Server Error. + Any exceptions that are not configured will be mapped to 500 Internal Server Error. * `config.action_dispatch.cookies_same_site_protection` configures the default value of the `SameSite` attribute when setting cookies. When set to `nil`, the @@ -723,16 +740,16 @@ Defaults to `'signed cookie'`. * `config.action_mailbox.logger` contains the logger used by Action Mailbox. It accepts a logger conforming to the interface of Log4r or the default Ruby Logger class. The default is `Rails.logger`. - ```ruby - config.action_mailbox.logger = ActiveSupport::Logger.new(STDOUT) - ``` + ```ruby + config.action_mailbox.logger = ActiveSupport::Logger.new(STDOUT) + ``` * `config.action_mailbox.incinerate_after` accepts an `ActiveSupport::Duration` indicating how long after processing `ActionMailbox::InboundEmail` records should be destroyed. It defaults to `30.days`. - ```ruby - # Incinerate inbound emails 14 days after processing. - config.action_mailbox.incinerate_after = 14.days - ``` + ```ruby + # Incinerate inbound emails 14 days after processing. + config.action_mailbox.incinerate_after = 14.days + ``` * `config.action_mailbox.queues.incineration` accepts a symbol indicating the Active Job queue to use for incineration jobs. When this option is `nil`, incineration jobs are sent to the default Active Job queue (see `config.active_job.default_queue_name`). It defaults to `:action_mailbox_incineration`. @@ -952,9 +969,9 @@ You can find more detailed configuration options in the * `:mutool` - The location of the mutool executable. * `:ffmpeg` - The location of the ffmpeg executable. - ```ruby - config.active_storage.paths[:ffprobe] = '/usr/local/bin/ffprobe' - ``` + ```ruby + config.active_storage.paths[:ffprobe] = '/usr/local/bin/ffprobe' + ``` * `config.active_storage.variable_content_types` accepts an array of strings indicating the content types that Active Storage can transform through ImageMagick. The default is `%w(image/png image/gif image/jpg image/jpeg image/pjpeg image/tiff image/bmp image/vnd.adobe.photoshop image/vnd.microsoft.icon image/webp)`. @@ -967,42 +984,43 @@ text/javascript image/svg+xml application/postscript application/x-shockwave-fla * `config.active_storage.queues.analysis` accepts a symbol indicating the Active Job queue to use for analysis jobs. When this option is `nil`, analysis jobs are sent to the default Active Job queue (see `config.active_job.default_queue_name`). The default is `nil`. - ```ruby - config.active_storage.queues.analysis = :low_priority - ``` + ```ruby + config.active_storage.queues.analysis = :low_priority + ``` * `config.active_storage.queues.purge` accepts a symbol indicating the Active Job queue to use for purge jobs. When this option is `nil`, purge jobs are sent to the default Active Job queue (see `config.active_job.default_queue_name`). The default is `nil`. - ```ruby - config.active_storage.queues.purge = :low_priority - ``` + ```ruby + config.active_storage.queues.purge = :low_priority + ``` * `config.active_storage.queues.mirror` accepts a symbol indicating the Active Job queue to use for direct upload mirroring jobs. When this option is `nil`, mirroring jobs are sent to the default Active Job queue (see `config.active_job.default_queue_name`). The default is `nil`. - ```ruby - config.active_storage.queues.mirror = :low_priority - ``` + ```ruby + config.active_storage.queues.mirror = :low_priority + ``` * `config.active_storage.logger` can be used to set the logger used by Active Storage. Accepts a logger conforming to the interface of Log4r or the default Ruby Logger class. - ```ruby - config.active_storage.logger = ActiveSupport::Logger.new(STDOUT) - ``` + ```ruby + config.active_storage.logger = ActiveSupport::Logger.new(STDOUT) + ``` * `config.active_storage.service_urls_expire_in` determines the default expiry of URLs generated by: - * `ActiveStorage::Blob#url` - * `ActiveStorage::Blob#service_url_for_direct_upload` - * `ActiveStorage::Variant#url` - The default is 5 minutes. + * `ActiveStorage::Blob#url` + * `ActiveStorage::Blob#service_url_for_direct_upload` + * `ActiveStorage::Variant#url` + + The default is 5 minutes. * `config.active_storage.routes_prefix` can be used to set the route prefix for the routes served by Active Storage. Accepts a string that will be prepended to the generated routes. - ```ruby - config.active_storage.routes_prefix = '/files' - ``` + ```ruby + config.active_storage.routes_prefix = '/files' + ``` - The default is `/rails/active_storage`. + The default is `/rails/active_storage`. * `config.active_storage.replace_on_assign_to_many` determines whether assigning to a collection of attachments declared with `has_many_attached` replaces any existing attachments or appends to them. The default is `true`. @@ -1012,11 +1030,12 @@ text/javascript image/svg+xml application/postscript application/x-shockwave-fla * `config.active_storage.resolve_model_to_route` can be used to globally change how Active Storage files are delivered. - Allowed values are: - * `:rails_storage_redirect`: Redirect to signed, short-lived service URLs. - * `:rails_storage_proxy`: Proxy files by downloading them. + Allowed values are: - The default is `:rails_storage_redirect`. + * `:rails_storage_redirect`: Redirect to signed, short-lived service URLs. + * `:rails_storage_proxy`: Proxy files by downloading them. + + The default is `:rails_storage_redirect`. ### Results of `config.load_defaults` diff --git a/guides/source/layouts_and_rendering.md b/guides/source/layouts_and_rendering.md index 19d2c7b7f9..7d1cfe7912 100644 --- a/guides/source/layouts_and_rendering.md +++ b/guides/source/layouts_and_rendering.md @@ -1213,27 +1213,27 @@ To pass a local variable to a partial in only specific cases use the `local_assi * `index.html.erb` - ```erb - <%= render user.articles %> - ``` + ```erb + <%= render user.articles %> + ``` * `show.html.erb` - ```erb - <%= render article, full: true %> - ``` + ```erb + <%= render article, full: true %> + ``` * `_article.html.erb` - ```erb -