I have something like this in my controllers. Both methods are private for the actual controller:
def new ... restore_user_data_from_cookie end def create ... save_used_data_in_cookie end
So basically user needs to enter some data just once and then they are stored in cookies and automatically filled in the new form.
Until now I had this functionality just in one controller for one model. But I’ve just added another controller and model and I can feel code smell.
I would like to avoid duplication, but I am not sure where to extract this code. Ideally I would like to have methods like these:
save_data_to_cookies(@model, [:attr1, attr2, ...]) restore_data_from_cookies(@model)
But I am not sure where to put these methods. In pure ruby script, I would create separate class for handling this. But what is the rails way?
Should I put it to ApplicationController? Or create some concern? Module? Also how should I test it? Just integration tests?
Many thanks in advance for all your answers!