资产application.css未声明,但它在清单中声明

时间:2017-09-24 14:41:01

标签: sprockets ruby-on-rails-5.1 rails-sprockets

我收到了这个错误:

ActionView::Template::Error (Asset `application.css` was not declared to be precompiled in production.
Declare links to your assets in `app/assets/config/manifest.js`.

  //= link application.css
and restart your server):
  • Rails 5.1.4

  • 链轮(4.0.0.beta5,4.0.0.beta4,3.7.1)

  • sprockets-rails(3.2.1,3.2.0,2.3.3)

Manifest.js

//= link_tree ../images

//= link_directory ../javascripts .js

//= link_directory ../stylesheets .css

Assets.rb

# Be sure to restart your server when you modify this file.

# Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = '1.0'

# Add additional assets to the asset load path.
# Rails.application.config.assets.paths << Emoji.images_path
# Add Yarn node_modules folder to the asset load path.
Rails.application.config.assets.paths << Rails.root.join('node_modules')

# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in the app/assets
# folder are already added.
# Rails.application.config.assets.precompile += %w( admin.js admin.css )

application.rb中

require_relative 'boot'

require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
# require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "action_cable/engine"
require "sprockets/railtie"
require "rails/test_unit/railtie"

1 个答案:

答案 0 :(得分:0)

在将重命名application.css更改为application.scss之后也得到了这一点。

此修复非常容易,只需使manifest.js文件如下所示即可:

//= link_tree ../images
//= link application.css

重新启动服务器,希望可以修复它。 祝你好运。