aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/asset_tag_helper.rb
diff options
context:
space:
mode:
authorwycats <wycats@gmail.com>2010-04-10 17:22:52 -0400
committerwycats <wycats@gmail.com>2010-04-10 17:22:52 -0400
commit87f7093ee3306f417e1136d947eba200d40ff8e7 (patch)
treeba70dbdaf67e12fc067bb5d8343d7681932452ef /actionpack/lib/action_view/helpers/asset_tag_helper.rb
parentee8e9d548472fb8cb8792a569e579c6513be77d6 (diff)
parent381f877bbbbf81d679f5be3b7ac7e961d41502bd (diff)
downloadrails-87f7093ee3306f417e1136d947eba200d40ff8e7.tar.gz
rails-87f7093ee3306f417e1136d947eba200d40ff8e7.tar.bz2
rails-87f7093ee3306f417e1136d947eba200d40ff8e7.zip
Merge branch 'master' into docrails_master
Diffstat (limited to 'actionpack/lib/action_view/helpers/asset_tag_helper.rb')
-rw-r--r--actionpack/lib/action_view/helpers/asset_tag_helper.rb53
1 files changed, 45 insertions, 8 deletions
diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
index e4ec17467e..563d9ec319 100644
--- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -501,16 +501,53 @@ module ActionView
end
end
+ # Web browsers cache favicons. If you just throw a <tt>favicon.ico</tt> into the document
+ # root of your application and it changes later, clients that have it in their cache
+ # won't see the update. Using this helper prevents that because it appends an asset ID:
+ #
+ # <%= favicon_link_tag %>
+ #
+ # generates
+ #
+ # <link href="/favicon.ico?4649789979" rel="shortcut icon" type="image/vnd.microsoft.icon" />
+ #
+ # You may specify a different file in the first argument:
+ #
+ # <%= favicon_link_tag 'favicon.ico' %>
+ #
+ # That's passed to +path_to_image+ as is, so it gives
+ #
+ # <link href="/images/favicon.ico?4649789979" rel="shortcut icon" type="image/vnd.microsoft.icon" />
+ #
+ # The helper accepts an additional options hash where you can override "rel" and "type".
+ #
+ # For example, Mobile Safari looks for a different LINK tag, pointing to an image that
+ # will be used if you add the page to the home screen of an iPod Touch, iPhone, or iPad.
+ # The following call would generate such a tag:
+ #
+ # <%= favicon_link_tag 'mb-icon.png', :rel => 'apple-touch-icon', :type => 'image/png' %>
+ #
+ def favicon_link_tag(source='/favicon.ico', options={})
+ tag('link', {
+ :rel => 'shortcut icon',
+ :type => 'image/vnd.microsoft.icon',
+ :href => path_to_image(source)
+ }.merge(options.symbolize_keys))
+ end
+
# Computes the path to an image asset in the public images directory.
# Full paths from the document root will be passed through.
- # Used internally by +image_tag+ to build the image path.
+ # Used internally by +image_tag+ to build the image path:
#
- # ==== Examples
- # image_path("edit") # => /images/edit
- # image_path("edit.png") # => /images/edit.png
- # image_path("icons/edit.png") # => /images/icons/edit.png
- # image_path("/icons/edit.png") # => /icons/edit.png
- # image_path("http://www.railsapplication.com/img/edit.png") # => http://www.railsapplication.com/img/edit.png
+ # image_path("edit") # => "/images/edit"
+ # image_path("edit.png") # => "/images/edit.png"
+ # image_path("icons/edit.png") # => "/images/icons/edit.png"
+ # image_path("/icons/edit.png") # => "/icons/edit.png"
+ # image_path("http://www.railsapplication.com/img/edit.png") # => "http://www.railsapplication.com/img/edit.png"
+ #
+ # If you have images as application resources this method may conflict with their named routes.
+ # The alias +path_to_image+ is provided to avoid that. Rails uses the alias internally, and
+ # plugin authors are encouraged to do so.
def image_path(source)
compute_public_path(source, 'images')
end
@@ -590,7 +627,7 @@ module ActionView
end
if mouseover = options.delete(:mouseover)
- options[:onmouseover] = "this.src='#{image_path(mouseover)}'"
+ options[:onmouseover] = "this.src='#{path_to_image(mouseover)}'"
options[:onmouseout] = "this.src='#{src}'"
end