I've been looking for a quick/easy way to access session variables inside of a model and I can't find a good, simple one.
I've found dozens of posts saying this is "very bad" and a "fundamental design flaw" of my application, all the way to much more colorful expressions of exactly how wrong this is. The reasoning I keep seeing is that models are a layer to the database, and therefore shouldn't have anything to do with a user session.
I get that, but I think it's pretty short-sighted.
You see, my app has no database - It pulls all of its data from an external API.
Aside from this fact, it needs to function the same way any other Rails application would, and it makes sense to have all of those records I'm pulling from the remote API handled via models. I still want to be able to use ActiveModel validators to validate data before I send it to the API, still want to keep controller code clean, etc.
But in order to talk to the API, I need to pass an authentication token, which I'm storing in the session.
Am I just way wrong in my thinking here? I don't think I am.
Also, anyone have a quick solution? Passing the session to the model method won't work, because it's a private method that's called by almost every other method in the model (to set the hTTP headers for my request).