Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including local (JS and CSS) files in local Sinatra Development

Tags:

sinatra

I've been trying out Sinatra on my local Windows machine. I want to include some local CSS and JS files. This is how the code looks in layout.erb

<script src="jquery.js" type="text/javascript"> </script> <link rel="stylesheet" href="reset.css" type="text/css" />  

All my files are in the same folder as app.rb

This is my app.rb

require 'rubygems' require 'sinatra'  get '/' do   erb :index end 

For some reason, I cant see these files included in my pages. When I view the source code and click on the file(JS/CSS) I see that - "Sinatra doesn't know this ditty"- error.

What am I doing wrong here?

like image 582
Prakhar Avatar asked Apr 12 '11 14:04

Prakhar


2 Answers

Move your static files(css/js) into a folder named public. Sinatra looks there with default settings.

If you want to change that behaviour have a look at this: Static Files

like image 87
scable Avatar answered Oct 12 '22 06:10

scable


By default Sinatra will look for static files in your public folder. You just need to make a folder called public in the same directory as your Ruby file, and place your JS and CSS files there.

like image 41
Todd Yandell Avatar answered Oct 12 '22 08:10

Todd Yandell