#=升级到Rails 5后无法正常工作

问题描述 投票:1回答:2

我将Rails 4.2.10应用程序升级到Rails 5.通过捆绑和一些弃用解决了错误。我能够启动Rails应用程序,但是当我尝试加载应用程序时,它失败并出现错误,css文件中的Invalid CSS after "#": expected id name, was "= require

我尝试使用@import,但它无法用于供应商/资产中的外部文件。不过,我想知道为什么它不再起作用了。在我的配置中,我有config.assets.precompile +=中的文件

在我的index.html.erb中,

<%= stylesheet_link_tag 'users' %>

在users.scss中,

#= require "dashboard/dx"

注意:我在Gemfile中使用sass-rails

我得到的错误,

Sass::SyntaxError in Dashboard::Users#index
Invalid CSS after "#": expected id name, was "= require "dash..."
Extracted source (around line #1):

#= require "dashboard/dx"
ruby-on-rails sprockets ruby-on-rails-5.2 rails-sprockets rails-upgrade
2个回答
0
投票

嘿,我认为错误是扔,因为在你典型的.scss文件中,你将不得不使用@import "dashboard/dx" and#= requiremight only work in.css`


0
投票

这条线的问题

 #= require "dashboard/dx" 

此语法不适用于.scss文件。要么你必须这样写

@import 'dashboard/dx'

或者使用.css扩展名重命名该文件。

注意:您也可以尝试使用.css.scss扩展名重命名。有时也可以使用它。

© www.soinside.com 2019 - 2024. All rights reserved.