Ramon Tayag
Ramon Tayag

Reputation: 16084

Rails 3.1 assets: Calling image_url in scss raises Unrecognized file type

When I call image_url('path/to/image.png') in my css.scss file, I get this error:

ActionView::Template::Error (Unrecognized file type: png)
  (in /home/ramon/source/unstilted/app/assets/stylesheets/admin.css.scss)):
    ...
  app/assets/stylesheets/admin.css.scss:134
  app/views/layouts/site_admin.html.haml:8:in `_app_views_layouts_site_admin_html_haml__354054488_99259250'

I'm using compass '0.12.0.alpha.0' from the rails_31 branch. Not sure if that's the issue. But I thought it was worth mentioning.

How do I include images in a css.scss file?

Upvotes: 1

Views: 2658

Answers (3)

Ramon Tayag
Ramon Tayag

Reputation: 16084

Apparently, it was something that wasn't working properly in that version of compass that I was using. See this thread for details.

Upvotes: 0

Chris
Chris

Reputation: 10338

actually, using background: image-url('name-of-image.png') seems to work just fine. (Note the hyphen instead of an underscore).

Upvotes: 4

Douglas F Shearer
Douglas F Shearer

Reputation: 26488

You need to name the file admin.css.scss.erb.

Then you can use view helpers in your css.

background-image: url(<%= image_url('foo.jpg') %>)

Not pretty, does the job.

Upvotes: 0

Related Questions