asset_path helper not including relative url when used in .css.erb #3365

pokonski opened this Issue Oct 19, 2011 · 10 comments


None yet
6 participants

pokonski commented Oct 19, 2011


I'm using Rails 3.1.1 and Passenger to deploy an application to /community sub-uri. In regular views this:

<%= asset_path "image.png" %> 

transforms into proper path:


But the same helper in my style.css.erb file produces:


I've seen a lot of older issues similar to this one, but none of them fixed this, so far. This basically renders asset_path useless in stylesheets, for now I'm resorting to asset_data_uri for inline inclusion.

EDIT: Same thing applies when using <%= asset_path "image.png" %> inside .js.erb files.

pdfrod commented Nov 6, 2011

I'm having the same problem. Using:

<%= asset_path('menu/down.gif') %>

renders the path:


instead of the expected:


ginjo commented Nov 10, 2011

I've been having the same or similar problem since 3.1 was released. Resolution of relative url roots for assets using css/sass/scss/erb appears to be on-again-off-again. There are several similar threads about this issue. Some of them:

With Rails 3.1.0, I solved the problem with the Sass::Rails::Helpers#public_path fix, mentioned in the above links. But with Rails 3.1.1, this fix no longer appears effective.

For me, with a fresh install of Rails 3.1.1 and all of it's dependencies, "image-url" in a scss file ignores the ENV['RAILS_RELATIVE_URL_ROOT'] environment variable, even though all of my view helpers resolve it correctly. Interestingly, "asset-url" DOES work.

In application.css.scss


resolves to



asset-url('myImage.png', 'image')

resolves to


I'm having the same problem with

<%= asset_path('zurb-nub-shell-hover.png') %>

But as ginjo said, asset-url works correctly so long as you are running the monkey patch here:

I'm running Rails 3.1.3.


pokonski commented Nov 30, 2011

But image-url requires SASS and I don't use that. Issue still stands, seems like a strictly Passenger+sprockets+erb issue.

I agree, it's still an issue. We don't use SASS either, but it's the only workaround we currently have short of not using the asset pipeline.


pokonski commented Nov 30, 2011

I guess it's time to dive into the code and fix it...

awendt commented Dec 1, 2011


Resolution of relative url roots for assets using css/sass/scss/erb appears to be on-again-off-again

That's my impression, too. Would be great if this could be fixed for good. Plus, Stackoverflow is full of work-arounds which all appear to be outdated despite their young age.


pokonski commented Dec 11, 2011

Gonna go ahead and harras José for a second. @josevalim, would you merge a fix for it if I made one? Don't want to code in vain so just asking!


pokonski commented Dec 12, 2011

Ok guys, I have some good news. I managed to fix the asset_path(and every other that generates paths as all use it) method in .erb assets in development mode. Basically what was happening is that Passenger uses ENV['RAILS_RELATIVE_URL_ROOT'] which was ignored by Sprockets.

With my fix ( it now generates proper paths for assets in sub-uri.

For production you still need to set that ENV variable before precompiling assets, just do this:

RAILS_RELATIVE_URL_ROOT="/suburi" rake assets:precompile

josevalim closed this in 5266eb9 Dec 12, 2011

josevalim closed this in af308ff Dec 12, 2011


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment