Asset filtered out and will not be served [duplica

2020-06-28 03:00发布

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.

3条回答
乱世女痞
2楼-- · 2020-06-28 03:34

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

config.assets.precompile += ['landing.css', 'landing.js']
查看更多
姐就是有狂的资本
3楼-- · 2020-06-28 03:45

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 .

查看更多
趁早两清
4楼-- · 2020-06-28 03:55

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

查看更多
登录 后发表回答