2

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
socratic_singh
  • 183
  • 1
  • 13
  • Is there a reason you have modified the `:public_folder` setting? `public` is [already the default for sinatra](http://www.sinatrarb.com/configuration.html). What does your file structure look like locally? – carols10cents Nov 03 '13 at 19:55
  • I added that in because I thought it might need to explicitly be defined when uploading to Heroku. I also tried renaming public as something else. – socratic_singh Nov 03 '13 at 20:40
  • If you try to go to http://*whatever-your-apps-name-is*.herokuapp.com/AL-thumbnail.png or http://*whatever-your-apps-name-is*.herokuapp.com/styles.css, do you get a 404 or do you see the image or CSS? If you go to http://*whatever-your-apps-name-is*.herokuapp.com and view source, what URL is in the ``'s `href`? – carols10cents Nov 03 '13 at 21:28
  • It gives a 404 not found. The tag for the stylesheet is `` – socratic_singh Nov 03 '13 at 23:17
  • Ok, what about at http://*whatever-your-apps-name-is*.herokuapp.com/public/styles.css ? And are you absolutely positive that you have added the files in your `public` directory to git and you have pushed the commits that added those files to your heroku repository? I know that sounds like I'm asking to make sure your computer is turned on, but please check again for me. If your git remote is named `heroku`, do `git log heroku/master --stat` and confirm that your files are in one of those commits. – carols10cents Nov 04 '13 at 01:40
  • Assets were definitely there as I checked in heroku console. I took someone else's functional sinatra-heroku app and ported across slices of my code until my app was complete and working - still don't know what the original problem was... – socratic_singh Nov 04 '13 at 17:28
  • Have a look at my answer (below) - it might b the gem 'rack-flash-session'? If so, then mark this as 'answered'.? – ThorstenC Jan 16 '14 at 08:53
  • Sorry, I resorted to starting an existing sinatra/heroku app and copying over the necessary code, so I have no way of testing your solution – socratic_singh Feb 05 '14 at 11:07

1 Answers1

1

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.

ThorstenC
  • 1,264
  • 11
  • 26