Incorrect image path when working in a subdirectory of my Rails application

I have a rails application running in a subdirectory like www.domain.com/sub . The problem is that if I set the image path in my CSS, for example

 /images/my_image.png 

it is interrupted when I upload it to my server. I need to install

 /sub/images/my_image.png 

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

I read something about the rails_relative_url_root environment rails_relative_url_root , but couldn't get it working.

Can anyone help me?

+4
source share
2 answers

You can use URLs relative to the stylesheet. In your CSS instead:

 /images/my_image.png 

make:

 ../images/my_image.png 
+2
source

If you are on OSX, you can configure the passenger to reflect the production environment (put the application in a folder / subdirectory) ... or you can look at the smaller / sass ... I have not used them much, but I believe that they can let you set asset paths programmatically

0
source

Source: https://habr.com/ru/post/1344157/


All Articles