Take the 2-minute tour ×

I'm trying to use a redirect_to in my controller while still keeping the validation error flash messages. In another post on this site, the suggested answer was to use:

flash[:error] = @object.errors redirect_to object_path

Unfortunately, if there are many errors (10 in my case), I get a ActionDispatch::Cookies::CookieOverflow error, since apparently the @object.errors object is too large to store in the cookie.

I'd really like to use redirect instead of render for other reason I have not mentioned due to their intricacy.

Any suggestions?

share|improve this question
add comment

3 Answers

You should use the activerecord store instead of cookie store as the latter cannot store large objects.


MyApp::Application.config.session_store :active_record_store

And then

rake db:sessions:create db:migrate

That should solve your problem

share|improve this answer
add comment

Store only the error messages, rather than the objects eg. @object.errors.full_messages.

share|improve this answer
add comment

You've got a 4kb limit on what you can store in a cookie, and when Rails converts your object into text for writing to the cookie its probably bigger than that limit.

Ruby on Rails ActionDispatch::Cookies::CookieOverflow error

That way this CookieOverflow Error occurs.

The easiest way to solve this one is, you need change your session_store and don't use the cookie_store. You can use the active_record_store by example.

Here is the 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'


(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.

share|improve this answer
add comment

Your Answer


