'How to link a css file with the Slim templating engine?
i am working on a little Sinatra/Slim project, and i want to include a css file. All works fine except that.
Here is my project "tree":
├── essai.rb
└── views
├── form.slim
└── style.css
And this is the head of form.slim:
html
head
title Vote
link href="style.css" rel='stylesheet' type='text/css'
I've tried "views/style.css", "../style.css",...etc. but Rake log the error "GET /style.css HTTP/1.1" 404. I know i have no routes for the css in sinatra, but i suppose there is a trick to avoid that... i hope :D
And i tried like i can see on the slim example page: file_path("style.css") but, i have a undefined method 'file_path' error, i guess because its a ruby function passed in args in the slim example.
Could someone tell me how can i do that? Thanks!
Solution 1:[1]
As stated in the accepted answer. However, his answer will be incomplete to those new to Sinatra. Yes you have to put your CSS file in public/css/
The code in your head should be
link rel="stylesheet" href="css/app.css" type="text/css"
Those new to Sinatra take note that your CSS file name can be anything, such as styles.css, app.css, main.css or whatever.
Here is a screenshot of my own project
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | dumbledad |

