alilland alilland - 1 year ago 58
Ruby Question

session[:id] variable not being picked up within another route from sinatra

I am following this tutorial here on setting up a user login

It says that in order to save a

in my route I would do something like this:

post '/login' do
@user = User.get_id(params['email'],params['password'])
session[:id] = @user # equals a numeric value of the matching user
redirect '/home'

however, when i get to my
route I am no longer able to access the
that was set in my
route, it returns

# this doesnt return the session id
# consequently I cant lookup my user records
get '/home' do
@user = User.object(session[:id]) # looks up user object with numeric value
erb :home

I have tried enabling sessions in my config controller, that didnt work either

module Controllers

class ApplicationController < Sinatra::Base

# . . . .

configure :production, :development do
enable :sessions, :logging



how do I make my app persist the
between routes?

Answer Source

Have you tried enable :sessions after you require your sinatra gem in your sinatra app? Not in your controller

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