When using Sinatra on Heroku, you can set your app up in such a way as to have a bug where your sessions will work locally but not on Heroku. The bug arises when you have the lines enable :sessions
and use Rack::Session::Cookie
both in your app. The solution I found was to remove the line enable :sessions
.
Created
June 9, 2011 21:15
-
-
Save JoshCheek/1017771 to your computer and use it in GitHub Desktop.
Sinatra + Heroku Session Bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "bundler/setup" | |
require 'sinatra' | |
get '/a' do | |
to_display = session[:to_remember] | |
session[:to_remember] = "a" | |
to_display | |
end | |
get '/b' do | |
to_display = session[:to_remember] | |
session[:to_remember] = "b" | |
to_display | |
end | |
enable :sessions # <-- this line will cause it to work locally but not on Heroku, just delete it. | |
use Rack::Session::Cookie | |
run Sinatra::Application |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source "http://rubygems.org" | |
gem "sinatra" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GEM | |
remote: http://rubygems.org/ | |
specs: | |
rack (1.3.0) | |
sinatra (1.2.6) | |
rack (~> 1.1) | |
tilt (< 2.0, >= 1.2.2) | |
tilt (1.3.2) | |
PLATFORMS | |
ruby | |
DEPENDENCIES | |
sinatra |
enable :sessions
turns on a bunch more options, but by default also does Rack::Session::Cookie. It's mostly authentication options (which you should look into).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was a life saver for me. Seems like
use Rack::Session::Cookie
andenable :sessions
don't play well together in general.