How to set “shortcut icon” in rails? [duplicate]

落花浮王杯 提交于 2019-12-07 04:37:47

问题


<head>
  <title>Application</title>
  <% link { :rel => "shortcut icon", :href => "/images/favicon.ico" } %>
</head>

I can't see the image which i set, What's wrong with the above code? How can i run successfully?


回答1:


See doc:

<%= favicon_link_tag 'favicon.ico' %>



回答2:


favicon_link_tag(source='/favicon.ico', options={})

<%= favicon_link_tag %>

generates

<link href="/favicon.ico" rel="shortcut icon" type="image/vnd.microsoft.icon" />

You may specify a different file in the first argument:

<%= favicon_link_tag '/myicon.ico' %>

That’s passed to path_to_image as is, so it gives

<link href="/myicon.ico" 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' %>

Method Like

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


来源:https://stackoverflow.com/questions/12950117/how-to-set-shortcut-icon-in-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!