Now From Home

Working from home

When Your Assets Doesn't Get an Asset_id...

… check that the asset does exist.

I had the following code in my application layout template:

application.html.erb
1
2
3
4
5
6
7
8
9
<!DOCTYPE html>
<html>
<head>
  <title>My webpage title</title>
  <%= stylesheet_link_tag 'default' %>
  <%= stylesheet_link_tag @current_subdomain %>
  <%= javascript_include_tag :defaults %>
  <%= csrf_meta_tag %>
</head>

It works great to load a custom stylesheet depending on the current subdomain, however I noticed that for some subdomains Rails was not adding the asset_id:

1
2
<link type="text/css" rel="stylesheet" media="screen" href="/stylesheets/default.css?1307960871">
<link type="text/css" rel="stylesheet" media="screen" href="/stylesheets/sample.css">

It is because sample.css must exist. stylesheet_link_tag does not check for the existence of the asset, and if it doesn’t exists it doesn’t add the asset timestamp.

Hope it saves you some time.

Comments