A Developer with a Pencil

Rails Request Repeats in Logs

Today we inherited on a multi-tenant Rails app for a new client that had a weird bug. Every GET request that was made in the application showed up twice in the l:low_brightness:

  Started GET "/vehicles
  Processing by VehiclesController#query as HTML

  Started GET "/vehicles
  Processing by VehiclesController#query as */*

As you can clearly tell from those two requests - Rails thinks the two requests are in different mime types, HTML and the general */* which led us to think, maybe there’s some kind of a resource request (CSS, Javascript or images) that has an empty url, something like:

  <img src="" />

Since the javascript_include_tag, styleheet_link_tag are protected against empty requests - we narrowed it down to image_tags - but it seems that if you pass an empty string or a nil value to image_tag - no request is being made.

Another thought we had is that we the actual link has some javascript remote behavior defined manually, and that the previous developers didn’t do some kind of an event propagation to prevent the link from doing what it is originally supposed to do - but the project had 0 custom javascript code and the link didn’t have any RJS setup.

So who is to blame?

When all else failed, we decided to break down the app views one by one. Luckily the perpetrator was one of our first suspects. Friends, meet favicon_link_tag. favicon_link_tag simply creates the HEAD section link tag to point to the favicon asset, and in the case of having no favicon address specified - the browser makes a request to the current url and that’s where the extra request in our logs comes from.


List of possible causes for repeating requests in the rails logs

  • Manual AJAX requests without some kind of e.preventDefault(), They’ll run, but the original link role is still going to kick in as well.
  • Empty asset link
  • Empty favicon asset link.