Scenario
I have an application in which I would like events logged to a third party (via a custom module leveraging Gabba mixed in to my models). The events are generated in the model, but the server side code to generate the events require access to current request's cookies.
MVC Problem
This is a specialization of the problem where the model needs data that's contained by the controller. Staying true to MVC, the model should not have access to the controller. The answer I've seen used is to pass the values needed as arguments to the model. While I agree with that approach in most cases, I don't think it's the best solution here because in general it's unknown and isn't the concern of the controller if the model is going to generate an event.
So for a concrete example:
Imagine a 'User' model has a static method called 'create'. The UsersController calls the create method with the user hash. The create method wants to publish a "user created" event to Gabba, but wants needs to resolve the google analytics cookies for the current request. It just doesn't seem right to send cookies to User#create.
What I've thought of is:
- Put the cookie values needed by the metrics module in some sort of global data store that is accessible by the models. (Where would be the best place?)
- Put the events in some sort of store, and have the controller run the event code at the end of processing the request.