plunkets plunkets - 1 year ago 100
CSS Question

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:



title Vote
link href="style.css" rel='stylesheet' type='text/css'

I've tried
,...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:
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!

Answer Source

Sinatra expects your css files files to reside in the public directory, not within the views directory by default.

So your project tree should look more like this.


Then you should be able to access it with your existing slim template.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download