Using ActiveRecord :: SessionStore for Sinatra Sessions

I want to save session data in a database using the ActiveRecord :: SessionStore module. I have been looking for this for success for a very long time. Either I do not use the correct search conditions, or I am blind to something very obvious.

I used this require ActiveRecord::SessionStore::Session in my code to enable session processing with an active record. It contains an error in the uninitialized constant ActiveRecord :: ActionDispatch . I assume I installed the actiondispatch module. Am I right?

Please keep in mind that this is my first shot with Ruby-Sinatra. I come from PHP.

So what should I use to force Sinatra to use database sessions using ActiveRecord?

+4
source share
2 answers

I ended up resolving the uninitialized constant ActiveRecord::ActionDispatch by adding an actionpack to my Gemfile application and requiring action_dispatch . You may also need require 'logger'

+2
source

Sinatra is a Rack application and allows you to add middleware. Middlewares can be connected to any rack platform. Search config.ru links in Sinatra Book

to create the config.ru file in the root directory of your application. and put something like this

 require 'my_app' use ActiveRecord::SessionStore run MyApp 
+1
source

All Articles