Adding icon to rails application

后端 未结 5 1688
悲哀的现实
悲哀的现实 2020-11-30 02:58

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

相关标签:
5条回答
  • 2020-11-30 03:30

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

    1. Add a file favicon.png to your public/assets folder
    2. In your $/app/views/layouts/application.html.erb modify the content of the <head> tag adding this <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.

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

    0 讨论(0)
  • 2020-11-30 03:33

    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.

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

    0 讨论(0)
  • 2020-11-30 03:34

    You can use Favicon Rails helper:

    <%= favicon_link_tag %>
    

    Or if you want another image than favicon.ico

    <%= favicon_link_tag 'another_image.ico' %>
    
    0 讨论(0)
  • 2020-11-30 03:48

    Put the favicon.ico under your public/ folder and then add <%= favicon_link_tag '/favicon.ico' %> to your <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.

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

    RAILS 3: rails server -p 12345

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

    0 讨论(0)
  • 2020-11-30 03:50

    You're talking about a favicon.

    Add this in the head part of your layout:

    <link rel="shortcut icon" href="/path_to_your_pic"/>
    
    0 讨论(0)
提交回复
热议问题