Ask Your Question

Revision history [back]

To access an image in an SCSS file on an app that is using Vite_Rails, you can use the following steps:

  1. Make sure your image is in the app/assets/images directory.

  2. In your SCSS file, use the url function to reference the image like this:

    background-image: url('/assets/images/your-image.png');
    

    Note that the path should start with /assets.

  3. In your application.scss file, make sure to import your SCSS file:

    @import 'your-file';
    
  4. In your HTML file, make sure to include the following tag:

    <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
    

    This tag will load the CSS file and make sure that your image is displayed correctly.

  5. Finally, run your app with the rails server command and access your page to see the result.