How to add an icon to rails 3.2

I know that new rail applications come with an empty favicon.ico file. I want to know how I am going to add an icon. I know that you can use the favicon_link_tag , but I'm not sure how to populate the favicon.ico file. Do you use favicon generators? If so, which one is better?

I also want to be able to cache it, do the rails do the same automatically?

thank

+72
ruby-on-rails favicon
Mar 28 '12 at 6:00
source share
11 answers

create your icon here: http://www.favicon.cc/ and type in the public / directory

UPDATE Favicon in a shared folder is not precompiled and can be cached for a long time. It seems that it is better to use favicon_link_tag to avoid problems with updating favicon. I do not know that the browser needs a root icon. According to favicon wiki , all modern browsers support

 <link rel="shortcut icon" href="favicon path" /> (favicon_link_tag) 
+68
Mar 28 '12 at 6:23
source share

Just add this to the <head></head> section of your layouts:

 <%= favicon_link_tag 'favicon.ico' %> 

Place the favicon.ico image in /app/assets/images/ if you are using the asset pipeline, and in /public/images/ if you haven’t.

In addition, there is an error when using Ruby 2.0 with Rails 3.0.20 (and possibly also 3.0.x), which throws an exception when trying to render favicon.ico.

The fix is ​​to put the following code in application_controller.rb:

  config.relative_url_root = "" 
+106
Apr 29 '13 at 22:16
source share

Although all of these answers suggest creating a 16x16 icon, in reality you have to create both 16x16 and 32x32 to support retina displays. None of the online generators could handle this.

The Mac has a great $ 5 app called Icon Slate , which makes it easy to create both formats in one ICO file.

On Windows, I used Axialis IconWorkshop with great success, but it is a much heavier tool and significantly more expensive at around € 50.

Both will create an ico file with 16x16 and 32x32 images inside it.

If you use the asset pipeline, use the app / assets / images folder, not / public. The number of browsers that ignore the link tag quickly approaches zero, so you should not jump through hoops to place them.

As mentioned in other answers, use this in head to display it:

 <%= favicon_link_tag 'favicon.ico' %> 
+9
04 Oct '13 at 17:11
source share

I highly recommend this option. It was easy to use and free http://converticon.com

+5
Jan 04 '13 at 0:44
source share

write in application.html.haml :

 = favicon_link_tag '/images/favicon.ico' 

place favicon.ico file in the directory:

 project/public/images 
+3
Jan 21 '15 at 13:22
source share

You pretty much need a 16x16 pixel image file called favicon.ico, and it should be available publicly at the root of your site.

You can always use the main image editor to convert your logo or other image to the .ico format. There are free options, such as Gimp, that can make such great icons based on an existing image better than online generators.

+2
Aug 04 '12 at 20:15
source share

I tried the links above and the services were not very easy to use. I find this link on another site, and it copied perfectly on my .png file and was very easy to use. I thought I would share this link as well, since I believe this is the best service.

http://www.chami.com/html-kit/services/favicon/

+1
Dec 31 '13 at 14:12
source share

I haven’t done this for many years, but Gimp is able to save .ico files with several images of different sizes. You just need to export to .ico format with some visible layers.

+1
Jul 10 '15 at 15:50
source share

To create an icon for all platforms (not just desktop browsers), you can use RealFaviconGenerator and the rails_real_favicon stone:

  • Go to RealFaviconGenerator and submit your image. You can create your own icon, platform on a platform: iOS, Android, etc.
  • Once your icon is ready, go to the "Rails" tab for steps to install your icon in your Rails project. Basically, you will be asked:
    • Add the rails_real_favicon Gemfile gem to you
    • Create a new file called favicon.json . This file describes the icons you just designed.
    • Run rails generate favicon to create icons and HTML code.
    • Add render 'favicon' to your layouts to embed HTML code in your pages.

The advantage of this solution is that it injects favicon files ( favicon.ico , apple-touch-icon.png , as well as browserconfig.xml and manifest.json ) into the asset pipeline.

Full disclosure: I am the author of RealFaviconGenerator.

+1
Dec 09 '15 at 9:23
source share

The solution I found for me was as follows:

  • Go to http://realfavicongenerator.net/favicon_checker and confirm that you have a good icon. If you do not, use their tool to create one (plus many other useful and related icons). Note: this requires that you have a good icon (e.g. PNG) to use as a sign for the icon.
  • Use the http://realfavicongenerator.net suggestion to use the ?v=version parameter to help avoid browser caching problems. It helped me.
  • Copy favicon.ico to public and app/assets/images . You will need only one, but if you don’t know which one to copy to both places, it won’t hurt ... or you can experiment to see which one works - use ?v=version to run the test.
  • Add the following line to the <head></head> section of your layouts in the app / views / layouts files (e.g. application.html.erb):

<%= favicon_link_tag 'favicon.ico' %>

Hope this gives a simple recipe. I am sure that if I miss something, someone can and will improve this answer.

0
Nov 10 '15 at 3:27
source share

I had a problem when I put the file in /public/favicon.ico , I am using AWS EBS.

I could fix the error.

The best solution for me was placed in the file /app/assets/images/favicon.ico and use = favicon_link_tag 'favicon.ico'

0
Aug 22 '17 at 20:56 on
source share



All Articles