Ruby-on-rails Rails 4 图标问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22736831/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 23:28:53  来源:igfitidea点击:

Rails 4 favicon issue

ruby-on-railsfavicon

提问by Samuel

Trying to add a favicon to my rails app, but doesn't seem to be working locally. Heres my code

尝试向我的 rails 应用程序添加收藏夹图标,但似乎无法在本地工作。这是我的代码

Aplication.html.erb (in the head section)

Aplication.html.erb(在头部部分)

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

Note:Favicon has been saved within my asset/images folder and the icon is 64x64 pixel

注意:Favicon 已保存在我的资产/图像文件夹中,图标为 64x64 像素

Is there anything thats been done wrong here?

这里有没有做错什么?

Thanks in advance

提前致谢

回答by Ole Henrik Skogstr?m

I think the address should be without the slash:

我认为地址应该没有斜线:

<%= favicon_link_tag 'favicon.ico' %>

回答by philippe_b

The proper use of favicon_link_tagis the immediate solution:

正确使用favicon_link_tag是直接的解决方案:

<%= favicon_link_tag 'favicon.ico' %>

However, a single favicon.icocan only address most desktop browsers. Mobile browsers can't cope with it but need higher resolution icons, like the Touch icon for iOS devices. You can get support for all browsers with RealFaviconGenerator:

但是,单个favicon.ico只能解决大多数桌面浏览器。移动浏览器无法应对,但需要更高分辨率的图标,例如 iOS 设备的 Touch 图标。您可以使用RealFaviconGenerator获得对所有浏览器的支持 :

  • Go to RealFaviconGeneratorand submit your picture. You can edit your icons platform-per-platform (Android, iOS...).
  • When the icons are ready, follow the instructions.
  • 转到RealFaviconGenerator并提交您的图片。您可以针对每个平台(Android、iOS...)编辑您的图标。
  • 当图标准备好后,按照说明进行操作。

The instructions are clear enough to setup the favicon, so there will be no path issue, no "extra slash" issue, etc.

说明足够清晰,可以设置 favicon,因此不会出现路径问题、“额外斜线”问题等。

Full disclosure: I'm the author of this site.

完全披露:我是这个网站的作者。

回答by Mirror318

Using rails 4.2.3, in my /publicfolder there was already a favicon. I simply replaced that and DID NOT ADD <%= favicon_link_tag 'favicon.ico' %>. Worked perfectly.

使用 rails 4.2.3,在我的/public文件夹中已经有一个 favicon。我只是替换了它,并没有添加<%= favicon_link_tag 'favicon.ico' %>。完美地工作。

Weird thing is I first tried with the favicon_link_tagand that somehow preventedthe favicon from showing up.

奇怪的是我第一次尝试使用favicon_link_tag并且以某种方式阻止了 favicon 出现。

回答by Murali Mohan

The proper use of favicon: add this <%= favicon_link_tag(source='favicon.ico')%>

favicon 的正确使用:添加这个 <%= favicon_link_tag(source='favicon.ico')%>