I am using the assets pipeline (in Rails 3.1.3) and am kind of struggling to make it work in production.
Situation
In my /app/assets/stylesheets
directory I have the following files:
application.css --> this is the default rails one
stylesheet.css --> This is my custom stylesheet
I spent a lot of time getting my stylesheet.css
included in the /public/assets/
directory in production (by running rake assets:precompile
) and I finally made it by adding the following line into in my application.rb
file:
config.assets.precompile += ['stylesheet.css']
I know have the right precompiled stylesheet.css
file in production.
My Problem
The problem I have is when using stylesheet_link_tag
with my stylesheet.css
file. It turns out:
<%= stylesheet_link_tag "stylesheet" %>
is resolved into <link href="/stylesheets/stylesheet.css" media="screen" rel="stylesheet" type="text/css">
in production I would expect the path to be resolved into /assets/stylesheet.css
just like it does in development.
What is even more surprising is that application.css
behaves perfectly even though <%= stylesheet_link_tag "application"%>
resolves into <link href="/stylesheets/stylesheet.css" media="screen" rel="stylesheet" type="text/css">
. What I don't understand is that the public/stylesheets/ directory does not exist in rails 3.1.
Any idea ?
Best Answer
Richard Hulse answers pointed me to the right direction. What happens is really subtle..
The answer to my question is Rails 3.1 assets has no fingerprint in production.
Basically, my project use mongoid instead of ActiveRecord. According to Mongoid documentation about configuration, the
application.rb
file can be modified to not includeActiveRecord
which means removing:And replacing it with:
I was so used to doing this manipulation with rails 3.0.x that I did not pay attention to the comment related to Rails 3.1
My problem was that I was not requiring sprockets !
Thank you all for your help !