Michael
Michael

Reputation: 1517

Rails assets aren't compiled properly

I'm having an unsettling issue with Ruby on Rails today. My assets aren't compiled: and by that, I mean that even when using asset:precompiled, they are simply not compiled.

I believe this will illustrate the problem better. After pre-compiling the assets, this is what /public/assets/application.js looks like:

// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
//= require jquery
//= require jquery-ui
//= require jquery_ujs
//= require twitter/bootstrap
//= require_tree .
;

Same goes for the css. The project works fine on other computers, so I suspect my configuration is at fault here. But what could possibly cause this kind of problem ? It's not like Rails doesn't try to precompile, but when he get to the files he just copy them to the asset folder without precompiling them.

Any clue on how to fix that ?

EDIT: Added output of asset:precompile

** Invoke assets:precompile (first_time)
** Execute assets:precompile
/home/plaristote/.rvm/rubies/ruby-2.0.0-p0/bin/ruby /home/plaristote/.rvm/gems/ruby-2.0.0-p0@visibleo_commApp/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
/home/plaristote/.rvm/rubies/ruby-2.0.0-p0/bin/ruby /home/plaristote/.rvm/gems/ruby-2.0.0-p0@visibleo_commApp/bin/rake assets:precompile:nondigest RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke assets:precompile:nondigest (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:nondigest

Upvotes: 0

Views: 350

Answers (2)

Matthew Clark
Matthew Clark

Reputation: 1965

I had precisely the same problem. I recently upgraded Ruby to 2.0.0 on production before seeing this problem. Normally, it takes a few minutes to precompile, but with this problem, it would only take seconds and generate no errors.

Since I manage Ruby with RVM, I was able to switch back to 1.9.3 easily and re-try precompiling. When I re-attempted precompiling with Ruby 1.9.3, I got errors about missing files, all related to bugs in third-party gem CSS. After I fixed those manually, precompiling succeeded (with 1.9.3).

However, I did not try switching back to Ruby 2.0.0 and precompiling after fixing the errors -- this was a production server that was suffering downtime, so once I got it back alive, I couldn't spare any more time. But my theory is that if I'd switched back to 2.0.0, the precompile would have succeeded. I may try to confirm this during scheduled downtime and update this answer.

So, it appears there's some kind of relationship with Ruby 2.0.0 and the precompile task not showing errors.

Upvotes: 0

tbem
tbem

Reputation: 605

Check if you have this in config/enviroments/production.rb:

# Disable Rails's static asset server (Apache or nginx will already do this)

config.serve_static_assets = false

# Compress JavaScripts and CSS

config.assets.compress = true

# Don't fallback to assets pipeline if a precompiled asset is missed

config.assets.compile = false

# Generate digests for assets URLs

config.assets.digest = true

Upvotes: 2

Related Questions