Brian
Brian

Reputation: 41

Wrong image path when running in a subdirectory of my Rails app

I have a rails app running in a subdirectory, like www.domain.com/sub. The problem is that if I set a image path in my css, like

/images/my_image.png

it breaks when I upload it to my server. I need to set

/sub/images/my_image.png

then it breaks in my development environment. The same problem occurs in my .js files.

I read something about the rails_relative_url_root environment variable, but couldn't get it to work.

Could anyone help me?

Upvotes: 4

Views: 686

Answers (2)

carols10cents
carols10cents

Reputation: 7014

You could use URLs relative to the stylesheet. In your CSS, instead of this:

/images/my_image.png

Do:

../images/my_image.png

Upvotes: 2

concept47
concept47

Reputation: 31736

If you're on OSX you can set up passenger to mirror your production environment (put app in /sub folder) ... or you can look into less/sass ... I'haven't used them much but I believe they might allow you set paths for assets programmatically

Upvotes: 0

Related Questions