aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb
diff options
context:
space:
mode:
authorPrem Sichanugrist <s@sikachu.com>2012-02-03 18:10:37 -0500
committerPrem Sichanugrist <s@sikachu.com>2012-02-04 17:57:05 -0500
commitbcd3b870cea567ffc626144a0292fba7797a4c78 (patch)
tree626019e59c940af5eaba30e0e84acfcfd6ed23d7 /actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb
parent20bc3d4aaa2ee13667b14cc20e2c31c32ef7489e (diff)
downloadrails-bcd3b870cea567ffc626144a0292fba7797a4c78.tar.gz
rails-bcd3b870cea567ffc626144a0292fba7797a4c78.tar.bz2
rails-bcd3b870cea567ffc626144a0292fba7797a4c78.zip
Add *_url helpers to get the full assets URL
Adds `image_url`, `javascript_url`, `stylesheet_url`, `audio_url`, `video_url`, and `font_url` to assets tag helper. These URL helpers will return the full path to your assets. This is useful when you are going to reference this asset from external host.
Diffstat (limited to 'actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb')
-rw-r--r--actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb b/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb
index d9f1f88ade..c67f81dcf4 100644
--- a/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb
+++ b/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb
@@ -87,6 +87,13 @@ module ActionView
end
alias_method :path_to_javascript, :javascript_path # aliased to avoid conflicts with a javascript_path named route
+ # Computes the full URL to a javascript asset in the public javascripts directory.
+ # This will use +javascript_path+ internally, so most of their behaviors will be the same.
+ def javascript_url(source)
+ URI.join(current_host, path_to_javascript(source)).to_s
+ end
+ alias_method :url_to_javascript, :javascript_url # aliased to avoid conflicts with a javascript_url named route
+
# Returns an HTML script tag for each of the +sources+ provided.
#
# Sources may be paths to JavaScript files. Relative paths are assumed to be relative