Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3.1: Why is rails_admin causing `rake asset:precompile` to fail?

EDIT

This question should be: Why is rails_admin causing rake asset:precompile to fail?

I'm upgrading from Rails 3.0 to 3.1 and enabling the asset pipeline. Somewhere along the way, rails_admin broke my asset precompiling:

-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       rake aborted!
       Undefined variable: "$red".
       (in /tmp/build_zkm1tzzdhdh6/vendor/bundle/ruby/1.9.1/bundler/gems/rails_admin-a887eee6e916/app/assets/stylesheets/rails_admin/base/theming.css.scss)
   
       Tasks: TOP => assets:precompile:primary
       (See full trace by running task with --trace)
       Precompiling assets failed, enabling runtime asset compilation
       Injecting rails31_enable_runtime_asset_compilation
       Please see this article for troubleshooting help:
       http://devcenter.heroku.com/articles/rails31_heroku_cedar#troubleshooting

What's going on here? $red is defined (in a different rails_admin .css file). So why isn't theming.css.scss able access it? How do I avoid this?

like image 624
thewillcole Avatar asked Feb 19 '12 04:02

thewillcole


2 Answers

I fixed this in the file config/environments/production.rb: I replaced the line

config.assets.precompile = ['*.js', '*.css']

to another

config.assets.precompile += %w(rails_admin/rails_admin.css rails_admin/rails_admin.js)

This solution is working for ruby 1.9.3 and rails 3.1

like image 79
Nikolay Moskvin Avatar answered Nov 03 '22 07:11

Nikolay Moskvin


Whoa! I found the problem -- it's a known issue on Heroku.

You can't blanket-include the rails_admin .css or .js files. i.e.:

  • make sure you don't have any catch-all *.(css|js) in config.assets.precompile
  • make sure you don't have any catch-all require_tree . in application.(css|js)

My problem is that I'm doing the former. That's causing my css files to be loaded in isolation, so that variables, like $red, aren't shared correctly between them.

like image 39
thewillcole Avatar answered Nov 03 '22 06:11

thewillcole