2

I've noticed that both helpers image_url and image-url work in my scss files, but they aren't generating the same path. What is the difference between these two functions?

Although I checked my environment configuration for the asset.prefix path, they generate different prefix when rendering assets.

all jazz
  • 2,007
  • 2
  • 21
  • 37
  • this [stackoverflow question](http://stackoverflow.com/questions/25457893/where-does-the-sass-font-url-method-get-defined) can answers you – dfang Apr 03 '15 at 01:51

2 Answers2

0

This is the main difference

For image url which is called asset_url or url_to_asset method with type image so it will go to image directory

   url_to_asset(source, {type: :image}.merge!(options))

For assets url you can call for js or any other assets(video,audio,stylesheet..)

 path_to_asset(source, options.merge(:protocol => :request))

https://github.com/rails/rails/blob/d4b0e5f59f599a386d43a7f4d005430e87ae7ec4/actionview/lib/action_view/helpers/asset_url_helper.rb#L316

Rajarshi Das
  • 11,778
  • 6
  • 46
  • 74
0

It is the same helper. From the documentation

When using the asset pipeline, paths to assets must be re-written and sass-rails provides -url and -path helpers (hyphenated in Sass, underscored in Ruby) for the following asset classes: image, font, video, audio, JavaScript and stylesheet.

-url is used for sass, _url is used for Ruby.

It is convention in css and sass to use hypen-seperated words for functions; whereas in Ruby, it is convention to use snakecase.

Both functions should have the same behaviour and hence generate the paths that point to the same asset directory. If they do not, then you are probably experiencing a bug similar to: sass-rails asset pipeline: generating image paths incorrectly; `url(/images/blah.png)` instead of `url(/assets/blah.png)`

Community
  • 1
  • 1
James Lawson
  • 8,150
  • 48
  • 47