Html 将图标添加到 rails 应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6130593/
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-08-29 08:46:19  来源:igfitidea点击:

Adding icon to rails application

htmlruby-on-rails

提问by Mo.

How can I add an icon to my Rails application (to show in tabs when opened in a browser, etc.)?

如何向 Rails 应用程序添加图标(在浏览器中打开时显示在选项卡中等)?

回答by JCorcuera

You can use Favicon Railshelper:

您可以使用Favicon Rails助手:

<%= favicon_link_tag %>

Or if you want another image than favicon.ico

或者,如果您想要其他图像而不是 favicon.ico

<%= favicon_link_tag 'another_image.ico' %>

回答by apneadiving

You're talking about a favicon.

你在谈论一个favicon.

Add this in the headpart of your layout:

head你的布局部分添加这个:

<link rel="shortcut icon" href="/path_to_your_pic"/>

回答by LennonR

Just so people know, the "document root" where you place your favicon.ico is the "public" folder. As a Rails newb I thought it would be in the root of the entire application.

只是让人们知道,您放置 favicon.ico 的“文档根目录”是“公共”文件夹。作为 Rails 新手,我认为它会在整个应用程序的根目录中。

Also, you may have to clear your cache for it show up.

此外,您可能需要清除缓存才能显示它。

回答by Mauricio Gracia Gutierrez

After reading and trying all this answers without success I ended up doing this

在阅读并尝试所有这些答案后没有成功,我最终做到了这一点

  1. Add a file favicon.pngto your public/assetsfolder
  2. In your $/app/views/layouts/application.html.erbmodify the content of the <head>tag adding this <link rel="icon" type="image/png" href="/assets/favicon.png">
  1. 将文件favicon.png添加到您的public/assets文件夹
  2. 在你的$/app/views/layouts/application.html.erb修改<head>标签的内容添加这个<link rel="icon" type="image/png" href="/assets/favicon.png">

No need to change the web_server configuration file (nginx, apache, etc) no need to precompile the assets.

无需更改 web_server 配置文件(nginx、apache 等)无需预编译资产。

Just stop and run/debug your web site, clear the cache from your browser and reopen the page. It should work

只需停止并运行/调试您的网站,从浏览器中清除缓存并重新打开页面。它应该工作

回答by jbatista

Put the favicon.icounder your public/folder and then add <%= favicon_link_tag '/favicon.ico' %>to your <head></head>

将 放在favicon.ico您的public/文件夹下,然后添加<%= favicon_link_tag '/favicon.ico' %>到您的<head></head>

Then if you try it and doesn't work out, even after you cleaning browser's cache, you should try run the server at a different port. By default, rails runs the server at port 3000.

然后,如果您尝试并没有成功,即使在您清理了浏览器的缓存之后,您也应该尝试在不同的端口上运行服务器。默认情况下,rails 在端口 3000 上运行服务器。

Try changing the port to something you haven't used before – run the app as:

尝试将端口更改为您以前从未使用过的端口 - 运行应用程序:

RAILS 3: rails server -p 12345

导轨 3:导轨服务器 -p 12345

RAILS 1/2: ruby script/server -p 12345

RAILS 1/2:ruby 脚本/服务器 -p 12345