I am using the assets pipeline (in Rails 3.1.3) and am kind of struggling to make it work in production.
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.
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 ?
1 What is the Asset Pipeline? The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages and pre-processors such as CoffeeScript, Sass, and ERB.
To compile your assets locally, run the assets:precompile task locally on your app. Make sure to use the production environment so that the production version of your assets are generated. A public/assets directory will be created. Inside this directory you'll find a manifest.
Two cleanup tasks: rake assets:clean is now a safe cleanup that only removes older assets that are no longer used, while rake assets:clobber nukes the entire public/assets directory. The clean task allows for rolling deploys that may still be linking to an old asset while the new assets are being built.
4.1 Precompiling Assets. Rails comes bundled with a rake task to compile the asset manifests and other files in the pipeline to the disk. Compiled assets are written to the location specified in config.
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 include ActiveRecord
which means removing:
require railties/all
And replacing it with:
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "rails/test_unit/railtie"
# require "sprockets/railtie" # Uncomment this line for Rails 3.1+
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 !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With