I have one page website only using HTML, CSS and JavaScript. I want to deploy the app to Heroku, but I cannot find a way to do it. I am now trying to make the app working with Sinatra.
.
|-- application.css
|-- application.js
|-- index.html
|-- jquery.js
`-- myapp.rb
And the following is the content of myapp.rb
.
require 'rubygems'
require 'sinatra'
get "/" do
# What should I write here to point to the `index.html`
end
You might consider moving the
index.html
file toviews/index.erb
, and defining an endpoint like:Putting files in
public
folder has a limitation. Actually, when you are in the root'/'
path is works correctly because the browser will set the relative path of your css file for example/css/style.css
and sinatra will look for the file in thepublic
directory. However, if your location is for example/user/create
, then the web browser will look for your css file in/user/create/css/style.css
and will the fail.As a workaround, I added the following redirection to correctly load css file:
the sinatra-assetpack gem offers a whole bunch of features. syntax is sweet:
while i am still having issues with rails assets pipeline i feel like i have much more control using sinatra-assetpack - but most of the times it just works with a few lines of code.
Without any additional configuration, Sinatra will serve assets in
public
. For the empty route, you'll want to render the index document.Routes should return a
String
which become the HTTP response body.File.read
opens a file, reads the file, closes the file and returns aString
.Add below line in main rb file