【问题标题】:SASS Compass image-width and image-height not working in Rails 4SASS Compass 图像宽度和图像高度在 Rails 4 中不起作用
【发布时间】:2016-04-26 18:18:22
【问题描述】:

在我的 Rails 4 项目中,我的 Gemfile.. 中有这个。

gem 'sass-rails', '~> 4.0.3'
gem 'compass-rails'

...这在我的application.sass 文件中...

@import "compass"

...这在我的 SASS style.sass 文件中...

.background
  $image: asset-path("my-image.jpg")
  background: url($image)
  width:  image-width($image)
  height: image-height($image)

使用上面的代码,我在浏览器中收到此错误...

Error compiling CSS asset, Type error: no implicit conversion of nil into String (in /Users/.../style.sass)

image-widthimage-height 的 Compass 功能似乎无法访问 my-image.jpg 文件。如果我将它们注释掉,我可以获得图像,但无法使用 Compass 使用它的宽度和高度。我非常希望能够使用 Compass 功能。谢谢。

【问题讨论】:

  • 然后我将gem 'sass-rails', '~> 4.0.3' 更改为gem 'sass-rails''(和捆绑),我仍然得到同样的错误。
  • asset-path 调用的结果是什么? image-width 和 image-height 函数需要一个相对于 config.rb 中的 image_path 设置的路径
  • 我确实从资产路径调用中获得了所需的图像。

标签: css ruby-on-rails sass compass-sass


【解决方案1】:

你试过了吗?

.background
  $image: "my-image.jpg"
  background: image-url($image)
  width:  image-width($image)
  height: image-height($image)

我认为这是因为 compass 的图像宽度和图像高度已经考虑到资产管道。玩得开心。

【讨论】:

    猜你喜欢
    • 2012-05-03
    • 1970-01-01
    • 2012-01-15
    • 1970-01-01
    • 1970-01-01
    • 2011-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多