Joe Half Face Joe Half Face - 2 years ago 71
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.

Answer Source

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

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