开发者

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?


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'


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 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜