首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

Heroku上的#<Rails :: Application :: Configuration的未定义方法`sass'

在 Heroku 上,<Rails::Application::Configuration 未定义方法sass' 可能会导致应用程序无法正常运行。为了解决这个问题,可以采取以下措施:

  1. 确保在Gemfile中已包含sass: 在 Heroku 上的 Gemfile 中添加 sass 库,以便在本地运行时加载 sass 库。
代码语言:txt
复制

gem 'sass'

代码语言:txt
复制
  1. 使用scss而不是sass: 在 Rails 项目中,考虑使用 scss(SCSS)而不是 sass,因为 scss 是从 Ruby 社区起源并更好地与 Rails 集成。

sass 替换为 scss,在 application.css.scss 文件中添加以下代码:

代码语言:txt
复制

*= require_tree .

*= require_self

代码语言:txt
复制
  1. 确保在application.rb文件中包含Sass::Script: 在 application.rb 文件中添加 Sass::Script 依赖,以确保能够正确加载 scss
代码语言:txt
复制

config.sass.load_paths << "#{Rails.root}/app/assets/stylesheets"

config.sass.include_paths << "#{Rails.root}/app/assets/stylesheets"

config.sass.use_importer = true

代码语言:txt
复制
  1. Gemfile中添加sass-rails: 在 Gemfile 中添加 sass-rails,以在 Heroku 部署时自动加载 sass 库。
代码语言:txt
复制

gem 'sass-rails', '~> 5.2'

代码语言:txt
复制
  1. 使用Sass::Rails::Application#config:

config/application.rb 文件中添加以下代码,以便在 Heroku 部署时自动配置 Sass::Script

代码语言:txt
复制

config.sass.load_paths = [File.expand_path('app/assets/stylesheets', dir),

代码语言:txt
复制
                         File.expand_path('vendor/assets/stylesheets', __dir__),
代码语言:txt
复制
                         File.expand_path('app/assets/fonts', __dir__),
代码语言:txt
复制
                         File.expand_path('vendor/assets/fonts', __dir__),
代码语言:txt
复制
                         ]

config.sass.include_paths = [File.expand_path('app/assets/stylesheets', dir),

代码语言:txt
复制
                         File.expand_path('vendor/assets/stylesheets', __dir__),
代码语言:txt
复制
                         File.expand_path('app/assets/fonts', __dir__),
代码语言:txt
复制
                         File.expand_path('vendor/assets/fonts', __dir__),
代码语言:txt
复制
                         ]

config.sass.compile_style = :compressed

config.sass.line_comments = false

代码语言:txt
复制
  1. 确保在application.css中正确引用application.scss:

application.css 文件中,确保正确引用 application.scss,如下所示:

代码语言:txt
复制

/*

  • This is a manifest file that'll be compiled with Sass.
  • It contains all the stylesheets required to render the default
  • layout.
  • You can configure the options for each tab in the console with:
  • rails asset pipeline:
  • production:
  • css_dir: app/assets/stylesheets
  • css: app/assets/stylesheets/application.css
  • js: app/assets/javascripts/application.js
  • development:
  • css_dir: app/assets/stylesheets
  • css: app/assets/stylesheets/application.css
  • js: app/assets/javascripts/application.js
  • Options:
  • css_dir: The directory for your custom css files.
  • css: The filename of your custom css file(s).
  • js_dir: The directory for your custom js files.
  • js: The filename of your custom js file(s).
  • In both cases, the file directive at the top of the
  • application.css file will be prepended to the list.
  • Available as an instance method on the application class. / = require_tree . *= require_self
  1. 重新启动服务器: 重新启动服务器,以使更改生效。

现在,在 Heroku 上的 Rails 应用程序中,您应该能够使用 sassscss 成功编译 CSS 档案。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

没有搜到相关的结果

领券