Answer the question
In order to leave comments, you need to log in
How to link to stylesheet file in .erb file?
Having mastered more or less HTML and CSS, I decided to start learning Ruby. While getting acquainted with the sinatra. And the question arose - how to connect a CSS table to a file with ERB resolution? Let's say there is a file ./index.rb
# ./index.rb
require "sinatra"
get "/" do
erb :index
end
<!-- ./views/index.erb -->
<!DOCTYPE html>
<html>
<head>
<title>sth</title>
</head>
<body>
<%- 10.times do -%>
Something;<br>
<%- end -%>
</body>
</html>
<!-- ./views/index.erb -->
<head>
<title>sth</title>
<style type="text/css">
body {
font-size: 16px;
font-family: Verdana;
background-color: rgba(222, 222, 222, 0.6)
}
</style>
</head>
Answer the question
In order to leave comments, you need to log in
Sinatra by default gives statics from the public folder. You need to create this folder (if it doesn't exist), create a css folder in it and include the style like this:
(note that there is no public in the style path)
JS scripts are also included.
PS At the same time, I recommend the site https://mkdev.me/ There is a course on the basics of ruby, on working with rails, as well as a free book-guide to web development. They also offer mentoring services.
You can try to connect as in normal HTML
<head>
<link rel="stylesheet" type="text/css" href="theme.css">
</head>
<%= stylesheet_link_tag 'theme' %>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question