We still have a few apps that store the errors collection of an ActiveRecord object in the flash[:error] hash. This always worked fine, but since switching to cookie store, sometimes we get an exception because the cookie data is greater than 4KB.
What happens is the ActiveRecord::Base object is stored in the ActiveRecord::Errors object. If this object is too big, the exception is raised.
I monkey patched the FlashNow object to nil the @base ivar in flash.now. Here is the code:
class ActionController::Flash::FlashNow def []=(k, v) newv = v.clone newv.instancevariableset(:@base, nil) if v.isa?(ActiveRecord::Errors) @flash[k] = newv @flash.discard(k) v end end
class ActionController::Flash::FlashHash def []=(k, v) newv = v.clone newv.instancevariableset(:@base, nil) if v.isa?(ActiveRecord::Errors) keep(k) super(k, newv) end end
This takes care of the problem without affecting any other part of the app. Just drop this code in an initializer and bob’s your uncle.
If you wanted it to build a product you’d find a way to get time to work on it. If you really wanted to start that new hobby you’d sacrifice something to find the time and money to do it.
I'll define a "Wannabe Entrepreneur" as someone who has never made money from their businesses. Here are the different types of wannabes.
In the past few years I've built go-carts, built a 200+ sq ft workshop, written several eBooks. How do I create a life where I have time to work on side projects?
Receive 5 Software projects mistakes we have made over the years and how to avoid them.