0

So I got an application based on rails (7.0.8.3)

Using bowerfile I've installed some additional js libs including jquery ui I've included a jquery-ui css styles into my application.css by sprockets directive

*=require jquery-ui/themes/base/core.css *=require jquery-ui/themes/base/datepicker.css *=require jquery-ui/themes/smoothness/theme.css 

those libs are installed to vendor/assets/bower_components/ directory . In the stylesheets some images are referred as url(images/bg.png) The path to the image is relative to the stylesheet file

In the dev url is 404, since there is no such file in the public directory (the files lives in jquery-ui/themes/smoothness/theme/images).

Since the whole setup is not something very rare in dev process, I'm wondering what I did wrong and what is "standard" way of including the 3rd party css that refers assets living deep in the vendor's lib folder?

3
  • The paths in a CSS file are relative to how they are served by the HTTP server and not the file system. Do you really need to use a library from 2007 that hasn't received support since 2021?
    – max
    CommentedApr 21 at 15:50
  • Well, let's say I need that library. My question was mostly on the education about supposed "rails-way" of doing that. My initial thought was that how to do that with the least setup for any front end library installed with bower-like stuff. I suppose lot of libraries are doing that: refer to the images from its css with the relative path to the css file, which looks like the only sensible way. And I was curious how would rails app keep the reference valid. I was thinking that sprockets after require should "rebase" all references to "absolute" urls that asre valid after assets precompilationCommentedApr 22 at 3:36
  • Sprockets will not rewrite normal CSS url() references. If you want to link to fingerprinted assets from the pipeline you would need to use ERB to interpolate the URLs into the compiled CSS or use a pre-compiler such as SASS that performs the same steps. If you want to use this old junk I would just ignore the assets pipeline and serve the assets directly from the public directory or the web server. github.com/rails/…
    – max
    CommentedApr 22 at 12:12

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.