开发者

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

开发者_JS百科
/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?


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

/images/my_image.png

Do:

../images/my_image.png


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜