Favicon in Ruby on Rails application [duplicate] - ruby-on-rails

This question already has answers here:
Adding icon to rails application
(5 answers)
Closed 9 years ago.
I put favicon.ico into /public/ folder and include the following code into layout page
<%= favicon_link_tag %>
But inspite of it, the icon doesn't display. What should I do?

I have struggled with the same. This is what worked for me:
<%= favicon_link_tag 'favicon.ico' %>
and moving the favicon.ico to the /public/images directory.
Good luck!

I don't know what favicon_link_tag is in your app but in general, there are two ways to create a favicon.
Put your icon file in your app root directory (/public). In this case, you don't have to do anything in your code. (does not work in seamonkey, works in all other browsers I know)
Place a link element in the code of your master view:
<link rel="shortcut icon" type="image/vnd.microsoft.icon" href="/relative/path/to/file.ico" />

Related

Hartl Rails tutorial ch. 5 doesn't load bootstrap automatically

At the point in Ch. 5 of the Hartl tutorial where he's showing off CSS/SCSS/Bootstrap styling for the first time (ch. 5.1.2), you're supposed to see the page transformed from an unstyled HTML page to a nifty styled page. But I wasn't seeing the change. It stayed unstyled.
I typed in the listings carefully (and even copied and pasted them from the website, just to be sure, after encountering this problem), tried switching to different gem version numbers (as other advice on similar problems said to do), etc.
Then I decided to insert in my application.html.erb layout the <link> to the Bootstrap CDN, as well as <div class="bootstrap-fluid"> (which I'm glad I learned from FreeCodeCamp) and that fixed the problem:
<head>
...
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<div class="container-fluid">
...
</div>
</body>
Apparently I had done nothing wrong otherwise...my guess is that the bootstrap-sass gem (or some other gem) was not supplying this information correctly.
I'm concerned that if I've put this code in my layout, stuff might break later on. Like, it's supposed to work without what I added, right? Any ideas how to make it work the way Hartl wants it to work?
UPDATE: Ugh. Typo! It turns out that I had misnamed custom.css.scss to custom.css.cscc. Well, that'll do it!
The only reason the Bootstrap CDN link helped was that my layout made use of some Bootstrap. When I started adding custom CSS to custom.css.cscc (sic!) I knew the file wasn't even being read. Lesson learned...type even more carefully.

Rails 4: favicon not showing

My favicon just won't show, in Chrome or Firefox. This is how I am rendering it in the <head> section:
<%= favicon_link_tag 'favicon.ico' %>
It is located in public/images.
This is the produced HTML:
<link rel="shortcut icon" type="image/x-icon" href="/images/favicon.ico">
Opening the link in my browser shows the icon correctly.
The favicon is not handled by the asset pipeline when its in the public folder, and this can cause caching problems.
See here: How to add favicon in rails 3.2 and Clear the cache from the Rails asset pipeline.
Use the favicon_link_tag and place the .ico file in /app/assets/images/ to get it into the asset pipeline.
If it still doesn't work after that, try clearing your browser cache, your rails cache, and restarting your rails server.

Rails pages are linking in non-existent css file when using Stylus

I am trying to use Stylus with a Rails 4 project, but the asset pipeline seems to be naming the compiled CSS wrong and/or linking to the wrong file. If I generate some assets (rails g assets static_pages) the served pages all end up trying to link to a file that doesn't exist:
<link data-turbolinks-track="true" href="/assets/static_pages.css?body=1" media="all" rel="stylesheet" />
I'm using the stylus gem and I've removed the default one for SASS from my Gemfile. I've also tried stylus_rails, but that seems to be deprecated and it didn't change anything anyways. Has anyone else encountered this issue when using stylus with rails?
I'm really at a loss here; any help would be appreciated. Thanks!

favicon the rails way

I followed the advice I found here on stackOverflow, and added the following to the section of my layouts/application.html.erb:
<%= favicon_link_tag '/favicon.ico' %>
favicon.ico is in my public folder I also tried to place it in the assets/images folder
I restarted the rails server (local development environment on the MAC, Rails 3.2.xxx), but I'm not seeing the favicon. Any ideas?
Three things to check:
Does the favicon_link_tag properly render in the HTML source of your document?
Does the favicon.ico URL that it renders point to a valid file, is the path wrong or do you maybe have a permissions issue with that?
Did you refresh your browser's cache? In most browsers, do so by holding Ctrl or Shift while reloading the website. See also: Wikipedia: Bypass your cache

Rails 3.1 application.css updates don't affect webpage

I'm using Rails 3.1. I'm starting to have a problem -- any time I update my application.css it doesn't update the CSS of the webpage I'm working on. The server seems to be fetching an old version of the CSS instead of keeping up with the changes I make in my application. What are some possible reasons and solutions for this? Does it perhaps have to do with precompilation? (By the way I'm of course doing this all on my local machine.)
I'm sorry but I can't really tell when this started happening - which would be useful. I had been working on other parts and came back to this a few weeks later to find out that the application.css file wasn't affecting any changes.
By the way, I haven't changed
<%= stylesheet_link_tag "application" %>
... it's still there in my application. Also, in-line CSS still works, which is why I know it's a problem with the application.css.
Go into your public folder and delete the assets folder. When you deployed (or did a push) it precompiled your assets.
Show as your Source Page or Log.
Try:
<%= stylesheet_link_tag :application %>
And tell where you have application.sass or application.scss
Go to tmp > cache
Delete assets folder
Only solution that worked for me

Resources