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

2019-05-02 12:04发布

This question already has an answer here:

<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?

2条回答
Summer. ? 凉城
2楼-- · 2019-05-02 12:20
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
查看更多
爷的心禁止访问
3楼-- · 2019-05-02 12:36

See doc:

<%= favicon_link_tag 'favicon.ico' %>
查看更多
登录 后发表回答