Asset filtered out and will not be served [duplica

2020-06-28 03:18发布

问题:

Asset filtered out and will not be served: add Rails.application.config.assets.precompile += %w( login.js ) to config/initializers/assets.rb and restart your server

I ge the above error when i try to run my application.

<% content_for :javascripts do %>
    <%= javascript_include_tag 'login' %>
<% end %>

I have placed all my js files in assets/javascripts, but still i get the above error.

回答1:

As an alternative solution, you can also comment out this line on development.rb:

config.assets.raise_runtime_errors

or set it to false

This will disable sprockets runtime errors (the "Asset filtered out and will not be served" yada yada error) in development.

Keep in mind that by doing this, you can mask production errors for assets: eg. some assets will be served in development but not in production. (see this)

Use it if you know what you're doing :)

hth



回答2:

You must include all js/css files that you include with #javascript_include_tag and #stylesheet_link_tag methods in Rails.application.config.assets.precompile array. Check out config/initializers/assets.rb (create if it does not exist). That's how it should look:

Rails.application.config.assets.precompile += %w( login.js )

Restart Rails server after editing.

By the way it is self-evident from error's text.

Check out Rails Assets Pipeline documentation for details: http://guides.rubyonrails.org/asset_pipeline.html .



回答3:

I am doing something similar, but I've added my additional assets in Production.rb

config.assets.precompile += ['landing.css', 'landing.js']