From ed7e8751542e72e360a80221321d69fa144a181c Mon Sep 17 00:00:00 2001 From: Mikhail Dieterle Date: Sat, 23 Aug 2014 22:13:22 +0300 Subject: recount files quantity --- guides/source/getting_started.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/getting_started.md b/guides/source/getting_started.md index 964bb30856..1769448531 100644 --- a/guides/source/getting_started.md +++ b/guides/source/getting_started.md @@ -1627,7 +1627,7 @@ controller. Again, we'll use the same generator we used before: $ bin/rails generate controller Comments ``` -This creates six files and one empty directory: +This creates five files and one empty directory: | File/Directory | Purpose | | -------------------------------------------- | ---------------------------------------- | -- cgit v1.2.3 From 078cc10d31ee39fa8960e6f491dbea3b368cbec7 Mon Sep 17 00:00:00 2001 From: Rashmi Yadav Date: Sat, 23 Aug 2014 21:44:03 +0200 Subject: [ci skip ]Document transform_values && transform_values! --- guides/source/active_support_core_extensions.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'guides') diff --git a/guides/source/active_support_core_extensions.md b/guides/source/active_support_core_extensions.md index 5ed392d43d..08b46c62eb 100644 --- a/guides/source/active_support_core_extensions.md +++ b/guides/source/active_support_core_extensions.md @@ -2862,6 +2862,20 @@ Active Record does not accept unknown options when building associations, for ex NOTE: Defined in `active_support/core_ext/hash/keys.rb`. +### Transform Values + +#### `transform_values` && `transform_values!` + +The method `transform_values` accepts a block and returns a hash that has applied the block operations to each of the values in the receiver + +```ruby +{nil => nil, 1 => 1, a: :a}.transform_values { |value| value.to_s.upcase } +# => {nil => "", 1 => "1", :a=> "A"} +``` +There's also the bang variant `transform_values!` that applies the block operations to values in the very receiver. + +NOTE: Defined in `active_support/core_text/hash/transform_values.rb` + ### Slicing Ruby has built-in support for taking slices out of strings and arrays. Active Support extends slicing to hashes: -- cgit v1.2.3 From 10db166aef3ac99183b8360512f62a1a2685ae40 Mon Sep 17 00:00:00 2001 From: Rashmi Yadav Date: Sun, 24 Aug 2014 01:31:37 +0200 Subject: [ci skip] document truncate_words --- guides/source/active_support_core_extensions.md | 33 +++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'guides') diff --git a/guides/source/active_support_core_extensions.md b/guides/source/active_support_core_extensions.md index 08b46c62eb..0bdbf1d696 100644 --- a/guides/source/active_support_core_extensions.md +++ b/guides/source/active_support_core_extensions.md @@ -1310,6 +1310,39 @@ In above examples "dear" gets cut first, but then `:separator` prevents it. NOTE: Defined in `active_support/core_ext/string/filters.rb`. +### `truncate_words` + +The method `truncate_words` returns a copy of its receiver truncated after a given number of `words`: + +```ruby +"Oh dear! Oh dear! I shall be late!".truncate_words(4) +# => "Oh dear! Oh dear!..." +``` +Ellipsis can be customized with the `:omission` option: + +```ruby +"Oh dear! Oh dear! I shall be late!".truncate_words(4, omission: '…') +# => "Oh dear! Oh dear!…" +``` + +Note in particular that truncation takes into account the length of the omission string. + +Pass a `:separator` to truncate the string at a natural break: + +```ruby +"Oh dear! Oh dear! I shall be late!".truncate_words(4, separator: ' ') +# => "Oh dear! Oh dear!..." +``` + +The option `:separator` can be a regexp: + +```ruby +"Oh dear! Oh dear! I shall be late!".truncate_words(4, separator: /\s/) +# => "Oh dear! Oh dear!..." +``` + +NOTE: Defined in `active_support/core_ext/string/filters.rb`. + ### `inquiry` The `inquiry` method converts a string into a `StringInquirer` object making equality checks prettier. -- cgit v1.2.3 From 52f430f6cc3b417d587a360dafed982eb2182244 Mon Sep 17 00:00:00 2001 From: Mikhail Dieterle Date: Sun, 24 Aug 2014 12:27:27 +0300 Subject: code quotes for classname --- guides/source/form_helpers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/form_helpers.md b/guides/source/form_helpers.md index 048eb9a6e3..1c57528db6 100644 --- a/guides/source/form_helpers.md +++ b/guides/source/form_helpers.md @@ -623,7 +623,7 @@ Rails provides the usual pair of helpers: the barebones `file_field_tag` and the ### What Gets Uploaded -The object in the `params` hash is an instance of a subclass of `IO`. Depending on the size of the uploaded file it may in fact be a StringIO or an instance of `File` backed by a temporary file. In both cases the object will have an `original_filename` attribute containing the name the file had on the user's computer and a `content_type` attribute containing the MIME type of the uploaded file. The following snippet saves the uploaded content in `#{Rails.root}/public/uploads` under the same name as the original file (assuming the form was the one in the previous example). +The object in the `params` hash is an instance of a subclass of `IO`. Depending on the size of the uploaded file it may in fact be a `StringIO` or an instance of `File` backed by a temporary file. In both cases the object will have an `original_filename` attribute containing the name the file had on the user's computer and a `content_type` attribute containing the MIME type of the uploaded file. The following snippet saves the uploaded content in `#{Rails.root}/public/uploads` under the same name as the original file (assuming the form was the one in the previous example). ```ruby def upload -- cgit v1.2.3 From 597f98cdaff6268700bbde4f232a02ca1f80dddd Mon Sep 17 00:00:00 2001 From: schneems Date: Sun, 24 Aug 2014 15:31:42 -0500 Subject: [ci skip] wrap to 80 chars --- guides/source/asset_pipeline.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/asset_pipeline.md b/guides/source/asset_pipeline.md index e31cefa5bb..ed76ab8f22 100644 --- a/guides/source/asset_pipeline.md +++ b/guides/source/asset_pipeline.md @@ -166,7 +166,8 @@ pipeline, the preferred location for these assets is now the `app/assets` directory. Files in this directory are served by the Sprockets middleware. Assets can still be placed in the `public` hierarchy. Any assets under `public` -will be served as static files by the application or web server. You should use +will be served as static files by the application or web server when +`config.serve_static_assets` is set to true. You should use `app/assets` for files that must undergo some pre-processing before they are served. -- cgit v1.2.3 From a05b46cb0f60d3bf562694b0c007ad3315d62b27 Mon Sep 17 00:00:00 2001 From: schneems Date: Sun, 24 Aug 2014 15:40:22 -0500 Subject: [ci skip] docs asset_pipeline#CDNs --- guides/source/asset_pipeline.md | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'guides') diff --git a/guides/source/asset_pipeline.md b/guides/source/asset_pipeline.md index ed76ab8f22..20afd4ef31 100644 --- a/guides/source/asset_pipeline.md +++ b/guides/source/asset_pipeline.md @@ -917,19 +917,27 @@ end ### CDNs -If your assets are being served by a CDN, ensure they don't stick around in your -cache forever. This can cause problems. If you use -`config.action_controller.perform_caching = true`, Rack::Cache will use -`Rails.cache` to store assets. This can cause your cache to fill up quickly. - -Every cache is different, so evaluate how your CDN handles caching and make sure -that it plays nicely with the pipeline. You may find quirks related to your -specific set up, you may not. The defaults NGINX uses, for example, should give -you no problems when used as an HTTP cache. - -If you want to serve only some assets from your CDN, you can use custom -`:host` option of `asset_url` helper, which overwrites value set in -`config.action_controller.asset_host`. +CDN stands for [Content Delivery +Network](http://en.wikipedia.org/wiki/Content_delivery_network), they are +primarily designed to cache assets all over the world so that when a browser +requests the asset, a cached copy will be geographically close to that browser. +If you are serving assets directly from your Rails server in production, the +best practice is to use a CDN in front of your application. + +A common pattern for using a CDN is to set your production application as the +"origin" server. This means when a browser requests an asset from the CDN and +there is a cache miss, it will grab the file from your server on the fly and +then cache it. For example if you are running a Rails application on +`example.com` and have a CDN configured at `mycdnsubdomain.fictional-cdn.com`, +then when a request is made to `mycdnsubdomain.fictional- +cdn.com/assets/smile.png`, the CDN will query your server once at +`example.com/assets/smile.png` and cache the request. The next request to the +CDN that comes in to the same URL will hit the cached copy. When the CDN can +serve an asset directly the request never touches your Rails server. Since the +assets from a CDN are geographically closer to the browser, the request is +faster, and since your server doesn't need to spend time serving assets, it can +focus on serving application code as fast as possible. + ```ruby asset_url 'image.png', :host => 'http://cdn.example.com' -- cgit v1.2.3 From d736e9e4ac7fd72749626d67f3a8c27d6e46d2bc Mon Sep 17 00:00:00 2001 From: schneems Date: Sun, 24 Aug 2014 15:40:55 -0500 Subject: [ci skip] docs asset_pipeline CDN set up --- guides/source/asset_pipeline.md | 64 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/asset_pipeline.md b/guides/source/asset_pipeline.md index 20afd4ef31..0db570a46c 100644 --- a/guides/source/asset_pipeline.md +++ b/guides/source/asset_pipeline.md @@ -938,9 +938,71 @@ assets from a CDN are geographically closer to the browser, the request is faster, and since your server doesn't need to spend time serving assets, it can focus on serving application code as fast as possible. +#### Set up a CDN to Serve Static Assets + +To set up your CDN you have to have your application running in production on +the internet at a publically available URL, for example `example.com`. Next +you'll need to sign up for a CDN service from a cloud hosting provider. When you +do this you need to configure the "origin" of the CDN to point back at your +website `example.com`, check your provider for documentation on configuring the +origin server. + +The CDN you provisioned should give you a custom subdomain for your application +such as `mycdnsubdomain.fictional-cdn.com` (note fictional-cdn.com is not a +valid CDN provider at the time of this writing). Now that you have configured +your CDN server, you need to tell browsers to use your CDN to grab assets +instead of your Rails server directly. You can do this by configuring Rails to +set your CDN as the asset host instead of using a relative path. To set your +asset host in Rails, you need to set `config.action_controller.asset_host` in +`config/production.rb`: ```ruby -asset_url 'image.png', :host => 'http://cdn.example.com' +config.action_controller.asset_host = 'mycdnsubdomain.fictional-cdn.com' +``` + +Note: You only need to provide the "host", this is the subdomain and root +domain, you do not need to specify a protocol or "scheme" such as `http://` or +`https://`. When a web page is requested, the protocol in the link to your asset +that is generated will match how the webpage is accessed by default. + +You can also set this value through an [environment +variable](http://en.wikipedia.org/wiki/Environment_variable) to make running a +staging copy of your site easier: + +``` +config.action_controller.asset_host = ENV['CDN_HOST'] +``` + + + +Note: You would need to set `CDN_HOST` on your server to `mycdnsubdomain +.fictional-cdn.com` for this to work. + +Once you have configured your server and your CDN when you serve a webpage that +has an asset: + +```erb +<%= asset_path('smile.png') %> +``` + +Instead of returning a path such as `/assets/smile.png` (digests are left out +for readability). The URL generated will have the full path to your CDN. + +``` +http://mycdnsubdomain.fictional-cdn.com/assets/smile.png +``` + +If the CDN has a copy of `smile.png` it will serve it to the browser and your +server doesn't even know it was requested. If the CDN does not have a copy it +will try to find it a the "origin" `example.com/assets/smile.png` and then store +it for future use. + +If you want to serve only some assets from your CDN, you can use custom `:host` +option your asset helper, which overwrites value set in +`config.action_controller.asset_host`. + +```erb +<%= asset_path 'image.png', host: 'mycdnsubdomain.fictional-cdn.com' %> ``` Customizing the Pipeline -- cgit v1.2.3 From 053dd0075c35a3f5a5dd67d68028d9e18886b738 Mon Sep 17 00:00:00 2001 From: schneems Date: Sun, 24 Aug 2014 15:42:39 -0500 Subject: [ci skip] docs CDN caching behavior --- guides/source/asset_pipeline.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'guides') diff --git a/guides/source/asset_pipeline.md b/guides/source/asset_pipeline.md index 0db570a46c..9a22ec5700 100644 --- a/guides/source/asset_pipeline.md +++ b/guides/source/asset_pipeline.md @@ -1005,6 +1005,23 @@ option your asset helper, which overwrites value set in <%= asset_path 'image.png', host: 'mycdnsubdomain.fictional-cdn.com' %> ``` +#### Customize CDN Caching Behavior + +A CDN works by caching content. If the CDN has stale or bad content, then it is +hurting rather than helping your application. The purpose of this section is to +describe general caching behavior of most CDNs, your specific provider may +behave slightly differently. + +##### CDN Request Caching + +While a CDN is described as being good for caching assets, in reality caches the +entire request. This includes the body of the asset as well as any headers. The +most important one being `Cache-Control` which tells the CDN (and web browsers) +how to cache contents. This means that if someone requests an asset that does +not exist `/assets/i-dont-exist.png` and your Rails application returns a 404, +then your CDN will likely cache the 404 page if a valid `Cache-Control` header +is present. + Customizing the Pipeline ------------------------ -- cgit v1.2.3 From 8ea49ec574b627b6936b739478401b43b8fb8aa5 Mon Sep 17 00:00:00 2001 From: schneems Date: Sun, 24 Aug 2014 15:43:27 -0500 Subject: [ci skip] docs CDN header debugging --- guides/source/asset_pipeline.md | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'guides') diff --git a/guides/source/asset_pipeline.md b/guides/source/asset_pipeline.md index 9a22ec5700..3d11d2ba82 100644 --- a/guides/source/asset_pipeline.md +++ b/guides/source/asset_pipeline.md @@ -1022,6 +1022,54 @@ not exist `/assets/i-dont-exist.png` and your Rails application returns a 404, then your CDN will likely cache the 404 page if a valid `Cache-Control` header is present. +##### CDN Header Debugging + +One way to check the headers are cached properly in your CDN is by using [curl]( +http://explainshell.com/explain?cmd=curl+-I+http%3A%2F%2Fwww.example.com). You +can request the headers from both your server and your CDN to verify they are +the same: + +``` +$ curl -I http://www.example/assets/application- +d0e099e021c95eb0de3615fd1d8c4d83.css +HTTP/1.1 200 OK +Server: Cowboy +Date: Sun, 24 Aug 2014 20:27:50 GMT +Connection: keep-alive +Last-Modified: Thu, 08 May 2014 01:24:14 GMT +Content-Type: text/css +Cache-Control: public, max-age=2592000 +Content-Length: 126560 +Via: 1.1 vegur +``` + +Versus the CDN copy. + +``` +$ curl -I http://mycdnsubdomain.fictional-cdn.com/application- +d0e099e021c95eb0de3615fd1d8c4d83.css +HTTP/1.1 200 OK Server: Cowboy Last- +Modified: Thu, 08 May 2014 01:24:14 GMT Content-Type: text/css +Cache-Control: +public, max-age=2592000 +Via: 1.1 vegur +Content-Length: 126560 +Accept-Ranges: +bytes +Date: Sun, 24 Aug 2014 20:28:45 GMT +Via: 1.1 varnish +Age: 885814 +Connection: keep-alive +X-Served-By: cache-dfw1828-DFW +X-Cache: HIT +X-Cache-Hits: +68 +X-Timer: S1408912125.211638212,VS0,VE0 +``` + +Check your CDN documentation for any additional information they may provide +such as `X-Cache` or for any headers they may + Customizing the Pipeline ------------------------ -- cgit v1.2.3 From 8c2b3c9178a9628f44c8880ddb8e79f379a54b99 Mon Sep 17 00:00:00 2001 From: schneems Date: Sun, 24 Aug 2014 15:44:09 -0500 Subject: [ci skip] docs CDN Cache-Control behavior --- guides/source/asset_pipeline.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'guides') diff --git a/guides/source/asset_pipeline.md b/guides/source/asset_pipeline.md index 3d11d2ba82..389e64f1b4 100644 --- a/guides/source/asset_pipeline.md +++ b/guides/source/asset_pipeline.md @@ -1070,6 +1070,30 @@ X-Timer: S1408912125.211638212,VS0,VE0 Check your CDN documentation for any additional information they may provide such as `X-Cache` or for any headers they may +##### CDNs and the Cache-Control Header + +The [cache control +header](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9) is a W3C +specification that describes how a request can be cached. When no CDN is used, a +browser will use this information to cache contents. This is very helpful for +assets that are not modified so that a browser does not need to re-download a +website's CSS or javascript on every request. Generally we want our Rails server +to tell our CDN (and browser) that the asset is "public", that means any cache +can store the request. Also we commonly want to set `max-age` which is how long +the cache will store the object before invalidating the cache. The `max-age` +value is set to seconds with a maximum possible value of `31536000` which is one +year. You can do this in your rails application by setting + +``` +config.static_cache_control = "public, max-age=31536000" +``` + +Now when your application serves an asset in production, the CDN will store the +asset for up to a year. Since most CDNs also cache headers of the request, this +`Cache-Control` will be passed along to all future browsers seeking this asset, +the browser then knows that it can store this asset for a very long time before +needing to re-request it. + Customizing the Pipeline ------------------------ -- cgit v1.2.3 From fa704ed6f4568dbabce713f7c4788575e91c09af Mon Sep 17 00:00:00 2001 From: schneems Date: Sun, 24 Aug 2014 15:44:32 -0500 Subject: [ci skip] docs can URL cache invalidation --- guides/source/asset_pipeline.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'guides') diff --git a/guides/source/asset_pipeline.md b/guides/source/asset_pipeline.md index 389e64f1b4..c5985ddaf4 100644 --- a/guides/source/asset_pipeline.md +++ b/guides/source/asset_pipeline.md @@ -1094,6 +1094,30 @@ asset for up to a year. Since most CDNs also cache headers of the request, this the browser then knows that it can store this asset for a very long time before needing to re-request it. +##### CDNs and URL based Cache Invalidation + +Most CDNs will cache contents of an asset based on the complete URL. This means +that a request to + +``` +http://mycdnsubdomain.fictional-cdn.com/assets/smile-123.png +``` + +Will be a completely different cache from + +``` +http://mycdnsubdomain.fictional-cdn.com/assets/smile.png +``` + +If you want to set far future `max-age` in your `Cache-Control` (and you do). +Then make sure when you change your assets that your cache is invalidated. For +example when changing the smiley face in an image from yellow to blue, you want +all visitors of your site to get the new blue face. When using a CDN with a the +Rails asset pipeline `config.assets.digest` is set to true by default so that +each asset will have a different file name when it is changed. This way you +don't have to ever manually invalidate any items in your cache. By using a +different unique asset name instead, your users get the latest asset. + Customizing the Pipeline ------------------------ -- cgit v1.2.3 From 4d600ed6000b2444ef3fcf279f13e4261d6e7274 Mon Sep 17 00:00:00 2001 From: schneems Date: Sun, 24 Aug 2014 23:33:31 -0500 Subject: [ci skip] fix grammar in docs --- guides/source/asset_pipeline.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/asset_pipeline.md b/guides/source/asset_pipeline.md index c5985ddaf4..a2927a50e9 100644 --- a/guides/source/asset_pipeline.md +++ b/guides/source/asset_pipeline.md @@ -1112,7 +1112,7 @@ http://mycdnsubdomain.fictional-cdn.com/assets/smile.png If you want to set far future `max-age` in your `Cache-Control` (and you do). Then make sure when you change your assets that your cache is invalidated. For example when changing the smiley face in an image from yellow to blue, you want -all visitors of your site to get the new blue face. When using a CDN with a the +all visitors of your site to get the new blue face. When using a CDN with the Rails asset pipeline `config.assets.digest` is set to true by default so that each asset will have a different file name when it is changed. This way you don't have to ever manually invalidate any items in your cache. By using a -- cgit v1.2.3 From 41739a2677ce52ea842c14f1bf3323256e0c6a10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=AA=E0=A5=8D=E0=A4=B0=E0=A4=A5=E0=A4=AE=E0=A5=87?= =?UTF-8?q?=E0=A4=B6?= Date: Tue, 26 Aug 2014 00:01:28 -0500 Subject: Fix typo in ActiveJob guide [ci skip] --- guides/source/active_job_basics.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/active_job_basics.md b/guides/source/active_job_basics.md index ae5d21d546..e2439b7816 100644 --- a/guides/source/active_job_basics.md +++ b/guides/source/active_job_basics.md @@ -174,7 +174,7 @@ class GuestsCleanupJob < ActiveJob::Base queue_as :default before_enqueue do |job| - # do somthing with the job instance + # do something with the job instance end around_perform do |job, block| -- cgit v1.2.3 From 0508da1acb9095b866a76983bf125722508861ca Mon Sep 17 00:00:00 2001 From: schneems Date: Tue, 26 Aug 2014 10:43:22 -0500 Subject: [ci skip] use NOTE instead of Note --- guides/source/asset_pipeline.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/asset_pipeline.md b/guides/source/asset_pipeline.md index a2927a50e9..15ec8e1feb 100644 --- a/guides/source/asset_pipeline.md +++ b/guides/source/asset_pipeline.md @@ -960,7 +960,7 @@ asset host in Rails, you need to set `config.action_controller.asset_host` in config.action_controller.asset_host = 'mycdnsubdomain.fictional-cdn.com' ``` -Note: You only need to provide the "host", this is the subdomain and root +NOTE: You only need to provide the "host", this is the subdomain and root domain, you do not need to specify a protocol or "scheme" such as `http://` or `https://`. When a web page is requested, the protocol in the link to your asset that is generated will match how the webpage is accessed by default. -- cgit v1.2.3 From a8511f314a55e3b263158882451c0d9149139b55 Mon Sep 17 00:00:00 2001 From: schneems Date: Tue, 26 Aug 2014 10:44:53 -0500 Subject: [ci skip] proper end to sentence --- guides/source/asset_pipeline.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/asset_pipeline.md b/guides/source/asset_pipeline.md index 15ec8e1feb..8809512d21 100644 --- a/guides/source/asset_pipeline.md +++ b/guides/source/asset_pipeline.md @@ -1068,7 +1068,7 @@ X-Timer: S1408912125.211638212,VS0,VE0 ``` Check your CDN documentation for any additional information they may provide -such as `X-Cache` or for any headers they may +such as `X-Cache` or for any additional headers they may add. ##### CDNs and the Cache-Control Header -- cgit v1.2.3 From ac0df594d5a5c3841126c51edbc3ff397a8eced7 Mon Sep 17 00:00:00 2001 From: schneems Date: Tue, 26 Aug 2014 10:45:41 -0500 Subject: [ci skip] docs grammar --- guides/source/asset_pipeline.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'guides') diff --git a/guides/source/asset_pipeline.md b/guides/source/asset_pipeline.md index 8809512d21..15d743fb33 100644 --- a/guides/source/asset_pipeline.md +++ b/guides/source/asset_pipeline.md @@ -1109,8 +1109,8 @@ Will be a completely different cache from http://mycdnsubdomain.fictional-cdn.com/assets/smile.png ``` -If you want to set far future `max-age` in your `Cache-Control` (and you do). -Then make sure when you change your assets that your cache is invalidated. For +If you want to set far future `max-age` in your `Cache-Control` (and you do), +then make sure when you change your assets that your cache is invalidated. For example when changing the smiley face in an image from yellow to blue, you want all visitors of your site to get the new blue face. When using a CDN with the Rails asset pipeline `config.assets.digest` is set to true by default so that -- cgit v1.2.3 From f0249bc578616e19624dd44383f76139ef86a75e Mon Sep 17 00:00:00 2001 From: Harshad Sabne Date: Sun, 31 Aug 2014 16:58:51 +0530 Subject: Highlight Class/Module [ci skip] --- guides/source/active_job_basics.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/active_job_basics.md b/guides/source/active_job_basics.md index e2439b7816..2fc290a80f 100644 --- a/guides/source/active_job_basics.md +++ b/guides/source/active_job_basics.md @@ -228,7 +228,7 @@ class TrashableCleanupJob end ``` -This works with any class that mixes in ActiveModel::GlobalIdentification, which +This works with any class that mixes in `ActiveModel::GlobalIdentification`, which by default has been mixed into Active Model classes. -- cgit v1.2.3 From 4b9d22e9591140729d9a27249cb8dd62e43d82ad Mon Sep 17 00:00:00 2001 From: Harshad Sabne Date: Sun, 31 Aug 2014 17:22:01 +0530 Subject: Update caching_with_rails.md [ci skip] Highlight methods --- guides/source/caching_with_rails.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/source/caching_with_rails.md b/guides/source/caching_with_rails.md index d0f3a596fe..cbcd053950 100644 --- a/guides/source/caching_with_rails.md +++ b/guides/source/caching_with_rails.md @@ -363,7 +363,7 @@ class ProductsController < ApplicationController end ``` -If you don't have any special response processing and are using the default rendering mechanism (i.e. you're not using respond_to or calling render yourself) then you've got an easy helper in fresh_when: +If you don't have any special response processing and are using the default rendering mechanism (i.e. you're not using `respond_to` or calling render yourself) then you've got an easy helper in `fresh_when`: ```ruby class ProductsController < ApplicationController -- cgit v1.2.3 From 077d28fb6652a94db190aa0239ceaee35404e0ff Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 3 Sep 2014 16:12:45 +0000 Subject: copy edit AS core ext changes [ci skip] --- guides/source/active_support_core_extensions.md | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'guides') diff --git a/guides/source/active_support_core_extensions.md b/guides/source/active_support_core_extensions.md index 0bdbf1d696..965de0c761 100644 --- a/guides/source/active_support_core_extensions.md +++ b/guides/source/active_support_core_extensions.md @@ -1312,12 +1312,13 @@ NOTE: Defined in `active_support/core_ext/string/filters.rb`. ### `truncate_words` -The method `truncate_words` returns a copy of its receiver truncated after a given number of `words`: +The method `truncate_words` returns a copy of its receiver truncated after a given number of words: ```ruby "Oh dear! Oh dear! I shall be late!".truncate_words(4) # => "Oh dear! Oh dear!..." ``` + Ellipsis can be customized with the `:omission` option: ```ruby @@ -1325,13 +1326,11 @@ Ellipsis can be customized with the `:omission` option: # => "Oh dear! Oh dear!…" ``` -Note in particular that truncation takes into account the length of the omission string. - Pass a `:separator` to truncate the string at a natural break: ```ruby -"Oh dear! Oh dear! I shall be late!".truncate_words(4, separator: ' ') -# => "Oh dear! Oh dear!..." +"Oh dear! Oh dear! I shall be late!".truncate_words(3, separator: '!') +# => "Oh dear! Oh dear! I shall be late..." ``` The option `:separator` can be a regexp: @@ -2895,19 +2894,19 @@ Active Record does not accept unknown options when building associations, for ex NOTE: Defined in `active_support/core_ext/hash/keys.rb`. -### Transform Values +### Working with Values #### `transform_values` && `transform_values!` -The method `transform_values` accepts a block and returns a hash that has applied the block operations to each of the values in the receiver +The method `transform_values` accepts a block and returns a hash that has applied the block operations to each of the values in the receiver. ```ruby -{nil => nil, 1 => 1, a: :a}.transform_values { |value| value.to_s.upcase } -# => {nil => "", 1 => "1", :a=> "A"} +{ nil => nil, 1 => 1, :x => :a }.transform_values { |value| value.to_s.upcase } +# => {nil=>"", 1=>"1", :x=>"A"} ``` There's also the bang variant `transform_values!` that applies the block operations to values in the very receiver. -NOTE: Defined in `active_support/core_text/hash/transform_values.rb` +NOTE: Defined in `active_support/core_text/hash/transform_values.rb`. ### Slicing -- cgit v1.2.3