rails4.0 session activerecord
Active Record Session Store
A session store backed by an Active Record class. A default class is provided, but any object duck-typing to an Active Record Session class with text session_id
and data
attributes is sufficient.
Installation
Include this gem into your Gemfile:
gem 'activerecord-session_store', github: 'rails/activerecord-session_store'
Run the migration generator:
rails generate active_record:session_migration
Then, set your session store in config/initializers/session_store.rb
:
Foo::Application.config.session_store :active_record_store
Configuration
The default assumes a sessions
tables with columns:
id
(numeric primary key),session_id
(string, usually varchar; maximum length is 255), anddata
(text or longtext; careful if your session data exceeds 65KB).
The session_id
column should always be indexed for speedy lookups. Session data is marshaled to the data
column in Base64 format. If the data you write is larger than the column's size limit, ActionController::SessionOverflowError will be raised.
You may configure the table name, primary key, and data column. For example, at the end of config/application.rb
:
ActiveRecord::SessionStore::Session.table_name = 'legacy_session_table'
ActiveRecord::SessionStore::Session.primary_key = 'session_id'
ActiveRecord::SessionStore::Session.data_column_name = 'legacy_session_data'
Note that setting the primary key to the session_id
frees you from having a separate id
column if you don't want it. However, you must set session.model.id = session.session_id
by hand! A before filter on ApplicationController is a good place.
Since the default class is a simple Active Record, you get timestamps for free if you add created_at
and updated_at
datetime columns to the sessions
table, making periodic session expiration a snap.
You may provide your own session class implementation, whether a feature-packed Active Record or a bare-metal high-performance SQL store, by setting
ActionDispatch::Session::ActiveRecordStore.session_class = MySessionClass
You must implement these methods:
self.find_by_session_id(session_id)
initialize(hash_of_session_id_and_data, options_hash = {})
attr_reader :session_id
attr_accessor :data
save
destroy
The example SqlBypass class is a generic SQL session store. You may use it as a basis for high-performance database-specific stores.
http://rubydoc.info/gems/activerecord-session_store/0.1.0/frames
rails4.0 session activerecord的更多相关文章
- 解决rails4.0中send_file文件下载两次的问题
之前在开发文件下载的功能时,我遇到了一个很奇怪的问题,点击下载链接,在chrome console中会出现两次请求,第一次返回200,下载的数据缓存在chrome的cache中,第二次返回304,直接 ...
- asp.net 2.0 Session丢失问题
可行的解决方法(本人已用): 1.Web.config文件修改sessionstate模式(默认为InProc) <sessionState mode="/> 2.开启ASP.N ...
- cas4.0 session中返回更多的用户信息
实现思路: 新增AccoutAttributeDao类继承StubPersonAttributeDao,重写getPerson方法.实际应用中我们只需要修改getPersion方法中的内容,根据实际情 ...
- 远程线程注入突破SESSION 0
远程线程注入突破SESSION 0 SESSION 0 隔离 在Windows XP.Windows Server 2003,以及更老版本的Windows操作系统中,服务和应用程序使用相同的会话(Se ...
- ruby -- 进阶学习(三)Strong Parameters在rail3.0和4.0中的区别
今天coding的时候遇到一个未知的类型,于是用puts logo_params.class查了下数据类型,然后google了一下发现是 Strong Parameter Strong paramet ...
- rails 4.0.2 + mongoid 对mongodb进行增删改查
新建项目 rails new mongoid_app --skip-active-record --skip-test-unit --skip-bundle create create README. ...
- ActiveRecord::StatementInvalid (Mysql2::Error: Incorrect string value:
今天碰到一个相当棘手的问题,那就是ActiveRecord::StatementInvalid (Mysql2::Error: Incorrect string value . 本来在本地测试是没有任 ...
- zookeeper源码分析之六session机制
zookeeper中session意味着一个物理连接,客户端连接服务器成功之后,会发送一个连接型请求,此时就会有session 产生. session由sessionTracker产生的,sessio ...
- Openfire的启动过程与session管理
说明 本文源码基于Openfire4.0.2. Openfire的启动 Openfire的启动过程非常的简单,通过一个入口初始化lib目录下的openfire.jar包,并启动一个 ...
随机推荐
- AngularJS 动画
AngularJS 提供了动画效果,可以配合 CSS 使用. AngularJS 使用动画需要引入 angular-animate.min.js 库. <script src="htt ...
- 用winform程序来了解委托和事件
一.浅谈委托 如果有个过winform 和webform 程序开发的小伙伴一定有个这样的感觉吧,点击Button直接就执行了那个方法,到此他是怎么实现了的呢,大家有考虑过没有? 回到正题,什么是委托呢 ...
- 【leetcode】Intersection of Two Linked Lists
题目简述: Write a program to find the node at which the intersection of two singly linked lists begins. ...
- conda安装包
前面讲了有关conda改变镜像提高安装速度,这里来解决很多实用C写的酷,在Windows下不好安装的解决方案 1. 寻找wheel预编译文件 没有的话 2.使用conda命令安装 没有该包的话 3.实 ...
- word使用笔记(1)
开始字母的格式也是宋体,只要全选后设置字体为Times New Roman即可,会自动跳过中文 新安的Mathtype字体有点奇怪,在样式里设置了一下,果然自定义为宋体了,改回Times New Ro ...
- 学习微信小程序之css9内边距
padding内边距 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...
- Kafka vs RocketMQ—— Topic数量对单机性能的影响-转自阿里中间件
引言 上一期我们对比了三类消息产品(Kafka.RabbitMQ.RocketMQ)单纯发送小消息的性能,受到了程序猿们的广泛关注,其中大家对这种单纯的发送场景感到并不过瘾,因为没有任何一个网站的业务 ...
- Python3的tkinter写一个简单的小程序
一.这个学期开始学习python,但是看了python2和python3,最后还是选择了python3 本着熟悉python的原因,并且也想做一些小程序来增加自己对python的熟练度.所以写了一个简 ...
- Daily Scrum Meeting 汇总
Alpha Daily Scrum Meeting --FirstDay(11.8) Daily Scrum Meeting --SecondDay(11.9) Daily Scrum Meeting ...
- AutoCAD .net 开发 SelectionFilter Foreach Linq 性能比较
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...