To access an image in an SCSS file on an app that is using Vite_Rails, you can use the following steps:
Make sure your image is in the app/assets/images
directory.
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
.
In your application.scss
file, make sure to import your SCSS file:
@import 'your-file';
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.
Finally, run your app with the rails server
command and access your page to see the result.
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
Asked: 2023-07-01 23:08:36 +0000
Seen: 11 times
Last updated: Jul 01 '23