socratic_singh
socratic_singh

Reputation: 183

Sinatra public assets not available when uploading to Heroku

I've just started working on a simple Sinatra app and when uploading it to Heroku. None of the files in the public folder seem to be available but it works fine locally.

Are there any obvious reasons this might be happening?

Right now the code is really simple:

require 'rubygems'
require 'sinatra'
require 'bundler/setup'
require 'haml'
require 'rdiscount'

set :static, true
set :public_folder, "#{File.dirname(__FILE__)}/public"

get '/' do
  haml :landing
end

__END__

@@ layout
%html
  %head
    %meta{charset: "utf-8"}/
    %meta{content: "width=device-width, initial-scale=1.0", name: "viewport"}/
    %meta{content: "", name: "description"}/
    %meta{content: "", name: "author"}/
    %title TIL
    %link{href: "http://yui.yahooapis.com/pure/0.3.0/pure-min.css", rel: "stylesheet"}
    %link{rel: "stylesheet", href: "/styles.css"}
  %body
  = yield

@@landing
%section.hero
  .container
    .pure-g-r
      .pure-u-1
        .logo
          ...
.container
  %hr/
  .pure-g-r
    .pure-u-2-3
      .padding-box
        :markdown
          ...
    .pure-u-1-3
      .padding-box
        ..
  %hr/
  .pure-g-r
    .pure-u-1
      .padding-box
        :markdown
          ...
  %hr/
  .pure-g-r
    .pure-u-1
      .padding-box
        %h2 ...
    .pure-u-1-3
      .padding-box
        %img.img-rounded{src: "GD-thumbnail.png"}/
        :markdown
          ...
    .pure-u-1-3
      .padding-box
        %img.img-rounded{src: "AL-thumbnail.png"}/
        :markdown
          ...
    .pure-u-1-3
      .padding-box
        %img.img-rounded{src: "BP-thumbnail.png"}/
        :markdown
          ...
  %hr/
  %footer
    .row
      .col-lg-12
        %p

Local file structure is:

TIL (folder)
- app.rb
- Gemfile
- Procfile
- public (folder)
  - AL-thumbnail.png
  - BP-thumbnail.png
  - GD-thumbnail.png
  - logo.png
  - styles.css

Upvotes: 2

Views: 977

Answers (1)

ThorstenC
ThorstenC

Reputation: 1314

Have a look in your Heroku log file:

heroku logs

If you can see something like

Rack::Flash::SessionUnavailable - Rack::Flash depends on session middleware.:

Then add

gem "rack-flash-session"

to you Gemfile.

Also add 'require 'rack/flash/test'' to you main file.

This will force heroku to load the desired middelware.

Upvotes: 1

Related Questions