Srisa
Srisa

Reputation: 1027

Use ActiveRecord::SessionStore for sessions in Sinatra

I want to store the session data in database using the ActiveRecord::SessionStore module. I have been searching for quite sometime for this without success. Either i am not using the proper search terms or i am being blind to something very obvious.

I have used this statement require ActiveRecord::SessionStore::Session in my code to enable session handling with active record. It conks out with the error uninitialized constant ActiveRecord::ActionDispatch . I assume that i have install the actiondispatch module. Am I correct?

Please bear in mind that this is my first shot with Ruby-Sinatra. I am coming from PHP.

So, what should i use to make Sinatra use database-based sessions using ActiveRecord?

Upvotes: 4

Views: 1481

Answers (2)

Ivy Evans
Ivy Evans

Reputation: 772

I ended up solving the uninitialized constant ActiveRecord::ActionDispatch error by adding the actionpack gem to my application's Gemfile and requiring action_dispatch. You might also have to require 'logger'

Upvotes: 2

irfn
irfn

Reputation: 560

Sinatra is a Rack based application and allows addition of middleware. Middlewares can be plugged into any Rack based framework. Search on references of config.ru in the Sinatra Book

so you would create a config.ru file in the root of your app. and put something like this

require 'my_app'
use ActiveRecord::SessionStore
run MyApp 

Upvotes: 1

Related Questions