ActiveAdmin资产预编译错误

ActiveAdmin给了我一个

Undefined mixin 'global-reset'. 

尝试运行时出错

 rake assets:precompile 

ActiveAdmin是0.3.4。 我的Gemfile中有ActiveAdmin和资产组,包括sass,coffee-rails和uglifier。

确实,正如@dimitar指出的那样,问题就在于捕获所有内容,因为资产管道正在尝试编译部分内容,并且因为它们不是自己编译的,所以会出现依赖性问题。

根据您的应用程序,您可能需要全部捕获,特别是如果您在多个子文件夹中有许多JS,CoffeScript和SCSS / SASS文件。 在这种情况下,您可能会遇到rails抱怨,因为删除catch all时没有为生产编译某些东西。

解决方案是有一个捕获所有排除SASS部分,_filename.css。[scss | sass],这将解决它(为我工作!)。 我还从其他activeadmin建议中包含了一些其他提示,包括要编译的一些ActiveAdmin依赖项。 这是我的代码:

  # 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 ) 

我偶然发现了这个。 我原来的问题是在我的production.rb文件中的config.assets.precompile指令中。 我在那里有一个正则表达式,它匹配来自activeadmin gem的一些资产,它们不应该与预编译匹配。 将选项更改为以下内容对我有用:

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

我遇到的有问题的代码块是这样的:

 # 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)$/] 

它匹配来自activeadmin gem的资产并将它们声明为独立清单,当资产管道尝试对它们进行编译时,会产生此错误。

有关config.assets.precompile指令如何在Rails中工作的更多详细信息,请查看此Gist 。

在CSS文件中,您最有可能:

 @include 'global-reset'; 

但是,您尝试导入全局重置,因此应将其更改为:

 @import 'global-reset'; 

希望这可以帮助!