favicon the rails way - ruby-on-rails

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

Related

Production error: "image is not present in the asset pipeline" although it is there and working in dev environment?

I'm new to devops and can't figure out what's going on. Today we pushed a branch to production where we are using new images for a view.
Everything worked fine in development environment, but when it was promoted to production we started getting errors related to the new images not being found in the asset pipeline
<div class="text-center my-10">
<%= link_to t("url.static_site") do %>
<%= image_tag "logo-white-no-background" %>
<% end %>
</div>
error:
The asset "logo-white-no-background" is not present in the asset pipeline.
I've tried running bundle exec rake assets:precompile locally to emulate what happens in production (as I understand everything under /assets is precompiled and served by the web server) and I don't get any errors.
The only thing that I find different in the docs is that I'm not passing the file extension in the image_tag, although like I said it is working find in development (and actually breaks if I add the extension in that environment).
Should I try forcing a pre-compile on production to see if it is loaded correctly?
What else can I try?
You will need to add the extension to make it work in production!
It shouldn't break it in development, make sure you run rails assets:clean and rails assets:clobber to clean out the compiled assets and that you have the right file extension!
The extension is a hint to not only browsers or but also some backend servers. Nobody forces developers to add the extension; however, you can see adding the extension as a good coding habit.
For example, your image is jpg, but the browser shows it as png. You found the image shown correctly maybe it's just happened to that browser guessed the file type correctly. In some scenarios like downloading the file from S3, if there is no extension provided, it will be served as a pdf file.
Btw, about your problem, because it didn't show the image in the production environment. You can first check the src from by inspecting the source code. If the browser cannot find the image file via that URL, the URL is just invalid. After inspecting the image's URL, you can try to generate the right URL then.

Rendering rails real favicon favicons in haml files

I'm having trouble getting Rails Real Favicon to work in my application and I think the problem is the way I'm trying to display the favicon in the head of the app/views/layouts/angular.html.haml, app/views/layouts/application.html.haml, and app/views/layouts/devise.html.haml files. Right now all of them have the line:
= render '/application/favicon’
I understand that when using Rails Real Favicon /application/favicon isn't a partial (it's a folder filled with the different favicon images), so render wouldn't work. Please excuse me for my weak Haml, but I’m not sure how to include that folder in the head of those three haml files. Any suggestions?
UPDATE
This was an issue with Chrome. Favicon generates properly in Firefox and Safari, but for some reason not on Chrome when testing locally, not even after clearing my cache and cookies. Works on Chrome after pushed to staging and production. Thanks all for your help and suggestions.
1.- first go to this site if you need to generate favicon in many
dimensions: https://www.favicon-generator.org/
2.- second go to this site and convert html generated in first
step to haml http://htmltohaml.com/
3.- third create partial and call it in header of your layout file
I am sure that will work.

In Refinery CMS, how do I replace the favicon?

I have replaced the file located at public/favicon.ico with my icon file. But when I load the page, I still see the default Refinery warped bumblebee icon.
I have done the various refresh tricks to ensure I'm not looking at a cache.
Looking at the source, the icon url is /assets/favicon.ico. When I load that url directly, I still see the old favicon.
I have also searched my project directory for other favicon files, but mine is the only one.
Finally got it. I copied my favicon file into the app/assets/images folder.
Then I used this tag in my head partial:
<%= favicon_link_tag image_path('favicon.ico?v=2') %>

Highcharts doesn't work on Heroku

I have a ruby on rails app that uses highcharts.
Locally it works like a charm, however when I push the app to Heroku, Highcharts stops working and the div tag that is supposed to contain the chart appears empty.
I even tested it with one of the Highcharts examples (which has only hardcoded data), and still nothing.
Figured it out: The problem was in the precompiling of assets. Turned out that highcharts was not precompiled
Added :
config.assets.precompile += ['rollover.js', 'highcharts.js']
to production.rb (i suppose application.rb should work as well)
and
to layout file.
(since i expected all javascript files gets compiled in application.jss i only had <%= javascript_include_tag "application" %> in my layout file)
Sounds like Highcharts is not loading - either because it isn't being pushed to Heroku or because it isn't being served properly. Go to the URL where highcharts.js should be and see if you get the JavaScript or a 404.
If you can reach highcharts.js without issue then the problem is most likely in the setup code. Check and see if the appropriate variables are loaded onto the page (using the web developer tools for the browser you are testing in) and if there are any JavaScript errors showing up when the page is loaded.
Using lazy highcharts gem. Googled for an hour Nothing worked out for me.
Finally I've copied highcharts.js from Vendor directory and pasted it to assets.
Viola!

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