noo*_*oob 74 favicon ruby-on-rails
我知道新的rails应用程序带有一个空的favicon.ico文件.我想知道如何添加一个favicon.我知道你可以使用favicon_link_tag帮助器,但我不知道如何填充favicon.ico文件.你使用favicon发电机吗?如果是这样,哪一个最好?
我也希望能够缓存它,rails也会自动执行此操作吗?
谢谢
Adr*_*the 114
只需将其添加到<head></head>布局部分:
<%= favicon_link_tag 'favicon.ico' %>
Run Code Online (Sandbox Code Playgroud)
/app/assets/images/如果您正在使用资产管道,请将favicon.ico图像放入,如果不是,则将其放入/public/images/.
此外,如果使用带有Rails 3.0.20(也可能是3.0.x)的Ruby 2.0,则会出现错误,这会在尝试渲染favicon.ico时引发异常.
修复是将以下代码放入application_controller.rb:
config.relative_url_root = ""
Run Code Online (Sandbox Code Playgroud)
gay*_*vat 69
例如,在这里生成您的favicon:http://www.favicon.cc/ 并放入public /目录
公共文件夹中的UPDATE Favicon未预编译,可能会被缓存很长时间.看起来最好使用favicon_link_tag来避免favicon更新问题.我不知道浏览器在root中需要favicon.根据favicon wiki,所有现代浏览器都保持着
<link rel="shortcut icon" href="favicon path" /> (favicon_link_tag)
Run Code Online (Sandbox Code Playgroud)
While all these answers are saying to create a 16x16 icon, the reality is you should be creating both a 16x16 and 32x32, in order to support retina displays. None of the online generators did a very good job with this.
On Mac, there is a great $5 app called Icon Slate, which allows you to easily create both formats in a single ICO file.
On Windows, I've used Axialis IconWorkshop with great success, but it's a much heavier-duty tool, and is significantly more expensive at about €50.
Both will create an ico file with both 16x16 and 32x32 images within it.
如果您正在使用资产管道,请使用app/assets/images文件夹而不是/ public.忽略link标签的边缘浏览器的数量正在快速接近零,因此跳过环以适应它们是不值得的.
如其他答案中所述,head在显示它时使用它:
<%= favicon_link_tag 'favicon.ico' %>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
51905 次 |
| 最近记录: |