Ask Your Question
2

How to access an image in an SCSS file on an app that is using Vite_Rails?

asked 2023-07-01 23:08:36 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-07-01 23:36:01 +0000

huitzilopochtli gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-07-01 23:08:36 +0000

Seen: 11 times

Last updated: Jul 01 '23