nvano
nvano

Reputation: 347

ActiveAdmin assets precompile error

ActiveAdmin is giving me an

Undefined mixin 'global-reset'.

error when it try to run

rake assets:precompile

ActiveAdmin is 0.3.4. I have ActiveAdmin and an assets group in my Gemfile with sass, coffee-rails and uglifier.

Upvotes: 2

Views: 7508

Answers (3)

David Pelaez
David Pelaez

Reputation: 1384

The problem is indeed, as @dimitar points out, the line with the catch all because the asset pipeline is trying to compile partials and since they aren't written to be compiled on their own, dependency issues appear.

Depending on your app, you might need that catch all, specially if you have many JS, CoffeScript and SCSS/SASS files in several child folders. In that situation you might encounter that rails complains because something isn't compiled for production when the catch all is removed.

The solution is to have a catch all that excludes the SASS partials, _filename.css.[scss|sass] and that would solve it (worked for me!). I also included some other tips from other activeadmin suggestions including exactly some ActiveAdmin dependencies to be compiled. Here's my code:

 # Include all JS files, also those in subdolfer or javascripts assets folder
 # includes for exmaple applicant.js. JS isn't the problem so the catch all works.
 config.assets.precompile += %w(*.js)
 # Replace %w( *.css *.js *.css.scss) with complex regexp avoiding SCSS partials compilation
 config.assets.precompile += [/^[^_]\w+\.(css|css.scss)$/]
 #Adding active_admin JS and CSS to the precompilation list
 config.assets.precompile += %w( active_admin.css active_admin.js active_admin/print.css )

Upvotes: 11

Dimitar
Dimitar

Reputation: 927

I've just stumbled on this. The problem I had turned out to be in the config.assets.precompile directive in my production.rb file. I had a regular expression there, which was matching some assets from the activeadmin gem, that should not be matched for precompilation. Changing the option to the following worked for me:

# Needed for the ActiveAdmin's manifest assets.
config.assets.precompile += ['active_admin.css', 'active_admin.js']

The problematic code block I had was this:

# This one effectively turns every js/css file, which starts with
# a letter or a number, into an includeable asset manifest (similar to
# what application.js and application.css already are).
# You may want to omit this line for your application.
config.assets.precompile += [/^[a-z0-9]\w+\.(css|js)$/]

It was matching assets from the activeadmin gem and declaring them as standalone manifests and when the asset pipeline tried to complie them, this error was produced.

For more details on how the config.assets.precompile directive works in Rails, check out this Gist.

Upvotes: 14

andrewpthorp
andrewpthorp

Reputation: 5106

In your CSS file, you most likely have:

@include 'global-reset';

However, you are trying to import your global reset, so you should change that to:

@import 'global-reset';

Hope this helps!

Upvotes: 0

Related Questions