Topic: Asset Pipeline Failing In Production

I am developing a new application with Ruby 1.9.2 and Rails 3.1. When I deploy the application in development mode, I find all my assets (images, CSS files, and JS files) listed individually in the HTML:

<link href="/assets/reset.css?body=1" media="screen" rel="stylesheet" type="text/css" />
<link href="/assets/application.css?body=1" media="screen" rel="stylesheet" type="text/css" />
<link href="/assets/forms.css?body=1" media="screen" rel="stylesheet" type="text/css" />
<script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
<script src="/assets/global.js?body=1" type="text/javascript"></script>
<script src="/assets/application.js?body=1" type="text/javascript"></script>

Note that the application.* files above are empty in content, but it doesn't matter because all the component CSS and JS files are listed individually. So the page looks as it should. This is development mode, so I don't really care that so many HTTP fetches are necessary.

When I deploy in production mode, I find this:

<link href="/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />
<script src="/javascripts/application.js" type="text/javascript"></script>

These application.* files are still empty because the contents of the component files are not copied into them, and with the component CSS and JS files not included indivudually, my page has no style or functionality. Also, the lone image on the page isn't displayed.

I have set config.serve_static_assets = true in production.rb. In fact, just for fun, I completely copied the contents of development.rb into production.rb, but the result is the same.

Any insight into what I can do to solve the problem is appreciated.

Thanks and Happy Holidays.

Re: Asset Pipeline Failing In Production

I am facing the same issue.
I tried copying the files manually to public folder, set config.serve_static_assets = true but still the application complains that files are not found.

Another interesting fact. My page has images and when they didn't show up, I opened firebug and on hovering the pointer over the empty blocks of picture, I do see thumbnails showing up properly in firebug!! which means that images were there just that Rails is not able to see them...


I have been struggling with this issue for past 3-4 days. I did not knew that production deployment in ails was such a hassle. I come from Java/J2EE back ground and deployments are much simpler.

Right now I have downloaded Phusion passenger and am trying to deploy my rails app in passenger.... may be webrick is not good for trial production deployment at all.

Any suggestions??

Re: Asset Pipeline Failing In Production

bundle exec rake assets:precompile

From the docs:

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.assets.prefix. By default, this is the public/assets directory.

You can call this task on the server during deployment to create compiled versions of your assets directly on the server. If you do not have write access to your production file system, you can call this task locally and then deploy the compiled assets.

The rake task is:
bundle exec rake assets:precompile

For faster asset precompiles, you can partially load your application by setting config.assets.initialize_on_precompile to false in config/application.rb, though in that case templates cannot see application objects or methods. Heroku requires this to be false.

If you set config.assets.initialize_on_precompile to false, be sure to test rake assets:precompile locally before deploying. It may expose bugs where your assets reference application objects or methods, since those are still in scope in development mode regardless of the value of this flag.

Joe got a job, on the day shift, at the Utility Muffin Research Kitchen, arrogantly twisting the sterile canvas snout of a fully charged icing anointment utensil.