aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHubert Łępicki <hubert.lepicki@amberbit.com>2014-05-08 13:35:31 +0200
committerHubert Łępicki <hubert.lepicki@amberbit.com>2014-05-08 20:51:59 +0200
commitdb9a5c5a1f8e2a1590f0ac9436587d58a67a629e (patch)
tree802cf0be729e3dd62883dfbe0f7248590d8ba8d6
parent5371106d530e64cfb221492714fb7cef32fa45c3 (diff)
downloadrails-db9a5c5a1f8e2a1590f0ac9436587d58a67a629e.tar.gz
rails-db9a5c5a1f8e2a1590f0ac9436587d58a67a629e.tar.bz2
rails-db9a5c5a1f8e2a1590f0ac9436587d58a67a629e.zip
Improve documentation for asset_url
Updated CHANGELOG.md with entry about :host in asset_url
-rw-r--r--actionview/CHANGELOG.md4
-rw-r--r--actionview/lib/action_view/helpers/asset_url_helper.rb9
-rw-r--r--guides/source/asset_pipeline.md8
3 files changed, 20 insertions, 1 deletions
diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md
index a6f6ac78db..36028122d1 100644
--- a/actionview/CHANGELOG.md
+++ b/actionview/CHANGELOG.md
@@ -87,5 +87,9 @@
*Piotr Chmolowski, Łukasz Strzałkowski*
+* Allow custom `:host` option to be passed to `asset_url` helper that
+ overwrites `config.action_controller.asset_host` for particular asset.
+
+ *Hubert Łępicki*
Please check [4-1-stable](https://github.com/rails/rails/blob/4-1-stable/actionview/CHANGELOG.md) for previous changes.
diff --git a/actionview/lib/action_view/helpers/asset_url_helper.rb b/actionview/lib/action_view/helpers/asset_url_helper.rb
index 86a84c1356..ae684af87b 100644
--- a/actionview/lib/action_view/helpers/asset_url_helper.rb
+++ b/actionview/lib/action_view/helpers/asset_url_helper.rb
@@ -147,7 +147,14 @@ module ActionView
# Computes the full URL to an asset in the public directory. This
# will use +asset_path+ internally, so most of their behaviors
- # will be the same.
+ # will be the same. If :host options is set, it overwrites global
+ # +config.action_controller.asset_host+ setting.
+ #
+ # All other options provided are forwarded to +asset_path+ call.
+ #
+ # asset_url "application.js" # => http://example.com/application.js
+ # asset_url "application.js", host: "http://cdn.example.com" # => http://cdn.example.com/javascripts/application.js
+ #
def asset_url(source, options = {})
path_to_asset(source, options.merge(:protocol => :request))
end
diff --git a/guides/source/asset_pipeline.md b/guides/source/asset_pipeline.md
index 52fc9726d9..950cfdca29 100644
--- a/guides/source/asset_pipeline.md
+++ b/guides/source/asset_pipeline.md
@@ -913,6 +913,14 @@ 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`.
+
+```ruby
+asset_url 'image.png', :host => 'http://cdn.example.com'
+```
+
Customizing the Pipeline
------------------------