2011-09-27, Tue

Ruby on Rails ActionDispatch::Cookies::CookieOverflow error

I recently encountered this error when trying to persist some form data using the session variable in Rails 3.

Turns out, the data I was trying to store exceeded 4k limit of the HTTP Cookie Specification, hence the CookieOverflow Error.

The easiest way around it is to change your Session storage option from CookieStore to something like ActiveRecordStore. By making this change, Rails will store the session data in a row in the database and set the unique id for the row in the cookie.

Here is how you can swap your Session storage to ActiveRecordStore in 3 easy steps.

1. Generate a migration that creates the session table

   rake db:sessions:create

2. Run the migration

   rake db:migrate

3. Modify config/initializers/session_store.rb from

   (App)::Application.config.session_store :cookie_store, :key => 'xxx'

to

   (App)::Application.config.session_store :active_record_store

Once you’ve done the three steps, restart your application. Rails will now use the sessions table to store session data, and you won’t have the 4kb limit.

Isaac Su

tags: activerecordstore cookie cookieoverflow cookiestore rails rake ruby session session_store

---

Comment

  1. Great. Thx. I just encountered this error and got this post most useful.

    Thanks Again.

    — tahniyat · Sep 28, 07:16 AM · #

  2. You’re most welcomed, tahniyat.

    — Isaac · Sep 29, 02:37 AM · #

  3. Thanks for your post !

    — Pierre-Julien · Feb 22, 11:47 AM · #

  4. cool worx perfect!

    — klaus · Apr 12, 03:10 PM · #

  5. Thank you!

    — Ravindra Nath · Apr 8, 09:55 PM · #

Commenting is closed for this article.

---