The attribute is filtered and will not be serviced: add `config.assets.precompile

I just ported my application to rails 4.1.0 from 4.1.rc2 . We started getting these errors for my JS files.

 ActionView::Template::Error: Asset filtered out and will not be served: add `config.assets.precompile += %w( my_js )` to `config/application.rb` and restart your server 
+43
ruby-on-rails-4
Apr 09 '14 at 18:06
source share
5 answers

Responding to a call from Heroku, Rails companions combined sanity checks with sprockets_better_errors gems in Rails 4.1. See https://github.com/rails/sprockets-rails/pull/84

The goal is to identify pipeline errors that you will see while creating the application in development mode.

You are probably using javascript_include_tag in the application layout instead of placing your JavaScript files in the app / assets / javascripts / folder.

You can transfer files to the app / assets / javascripts / folder.

In addition, you need to update the config / application.rb file to include:

 config.assets.precompile += %w( my_js ) 

Please note that the file name must not contain the .js extension.

+50
Apr 10 '14 at 1:07
source share

If you added something like stylesheet_link_tag params[:controller] to the application layout header because you have separate JS applications on different controllers, but with the same basic layout, you will be very unhappy with this. A quick way to overcome this and continue working (but maybe not the final solution) with all pre-compiled assets is to add the following to /config/initializers/assets.rb:

 Rails.application.config.assets.precompile += [/.*\.js/,/.*\.css/] 

Please note that this is the same as for .js.coffee and .css.scss , .js and .css .

+30
Sep 28 '14 at 7:09
source share

Ideally, @zilojko's solution works, but I also have an active admin in this application. Therefore, looking a little further, I found the following solution:

 Rails.application.config.assets.precompile += %w(*.svg *.eot *.woff *.ttf *.gif *.png *.ico) Rails.application.config.assets.precompile << /\A(?!active_admin).*\.(js|css)\z/ 

Just add the lines above: /config/initializers/assets.rb

The asset precompilation code above when skipping active admin files. so that they are not processed twice or out of turn, which leads to errors.

+4
Feb 06 '15 at 12:41
source share

Yes, after reading the error in the browser, all I did was add the following line of code:

 Rails.application.config.assets.precompile += %w( depot.css ) 

In the file /config/initializers/assets.rb and it worked.

+3
Feb 27 '15 at 16:19
source share

You can remove <%= javascript_include_tag 'xxx' %> from your erb, and add this to assets/javascript/name_space/index.js.coffee

 #= require ./xxx 
0
Mar 21 '17 at 7:58
source share



All Articles