I want to have the home page (root of the website), check if a cookie exists for a user being logged in, and then based off of that determining whether or not to load the sign up page (landing page) or the feed of the user logged in.
Where would I have this check occur?
I’ve kept it in the controller for now, but based on some articles I’ve read (such as Skinny Controller, Fat Model, I’m not sure that’s the right place to keep it in.
Skinny Controller, Fat Model says that logic should be implemented in the model, since it allows better code reuse. The reasoning is that while a controller is tied to a single user action(or group of user actions), the model is used through the application, so putting the code in it allows to reuse it wherever we use the module.
This, however, applies only to code that operates on model data. In your case, you want to check for the existence of a cookie. Cookies are not related to a specific model – they are part of the HTTP request – so the natural place for them is the controller, since it’s the controller’s job to receive the user action and decide how to respond to it.
Still – this is code you’ll want to reuse(I’m assuming you’ll want to perform that check for many pages), so I wouldn’t tie it to a specific controller – it needs to be shared among all controllers. In RoR, for example, you’ll put it in the ApplicationController
– the base class for all controllers used in your application. I don’t know what framework you are using, or if you are rolling your own, but you should look for something similar.