Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improve documentation for asset_url

Updated CHANGELOG.md with entry about :host in asset_url
  • Loading branch information...
commit db9a5c5a1f8e2a1590f0ac9436587d58a67a629e 1 parent 5371106
@hubertlepicki hubertlepicki authored
View
4 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.
View
9 actionview/lib/action_view/helpers/asset_url_helper.rb
@@ -147,7 +147,14 @@ def asset_path(source, options = {})
# 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
View
8 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
------------------------
Please sign in to comment.
Something went wrong with that request. Please try again.