Joe Half Face Joe Half Face - 10 months ago 33
Ruby Question

Sinatra doesn't load assets

I have a sinatra landing page. Server starts by execution

in root folder.

For example:

get '/en' do
I18n.locale = 'en'
erb :index, locals: {langswitch: "/ru", current_locale: "en"}

and works well.

This page has:

<link rel="stylesheet" type="text/css" href="index.css">

And if I open this link, it points to
, retrieves css file and renders page as expected.

However, there is also

get '/agreement/en' do
I18n.locale = 'en'
erb :agreement, locals: {langswitch: "/ru", current_locale: "en"}

If I visit the same link from this page, it instead leads to
, instead of
and fails to retrieve file.

Same with all of my images, other css files.


First you need to put all your assets in public folder. Then you need to modifie <link rel="stylesheet" type="text/css" href="index.css"> to <link rel="stylesheet" type="text/css" href="/index.css">. So all you need to do is to put / before index.css