Skip to content

Commit

Permalink
Improve documentation for asset_url
Browse files Browse the repository at this point in the history
Updated CHANGELOG.md with entry about :host in asset_url
  • Loading branch information
hubertlepicki committed May 8, 2014
1 parent 5371106 commit db9a5c5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions actionview/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
9 changes: 8 additions & 1 deletion actionview/lib/action_view/helpers/asset_url_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions guides/source/asset_pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------------------

Expand Down

0 comments on commit db9a5c5

Please sign in to comment.