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.
Great. Thx. I just encountered this error and got this post most useful.
Thanks Again.
— tahniyat · Sep 28, 07:16 AM · #
You’re most welcomed, tahniyat.
— Isaac · Sep 29, 02:37 AM · #
Thanks for your post !
— Pierre-Julien · Feb 22, 11:47 AM · #
cool worx perfect!
— klaus · Apr 12, 03:10 PM · #
Thank you!
— Ravindra Nath · Apr 8, 09:55 PM · #