Are session aware Models a bad thing?

Posted by kevtufc on Programmers See other posts from Programmers or by kevtufc
Published on 2012-11-27T11:42:46Z Indexed on 2012/11/27 23:29 UTC
Read the original article Hit count: 176

Filed under:
|
|

I'm thinking specifically in Rails here, but I suspect this is a wider question.

In a Rails web application I'm using data from the session in models in order that the models know who is logged in. I use this in a method which filters out some data from the database depending on a very simple permissions system.

The thing is: using sessions in models in Rails requires a bit of a workaround. It works, but I've a feeling that it's something that I shouldn't be doing and I'm worried there's a big gotcha I'm missing.

I suppose the Right Thing To Do would be to return all the data and filter out the not-wanted bits in the controller before passing that to the view, but doing it in the model seems to avoid quite a bit of code duplication and so feels "cleaner."

Can anyone tell me why or shouldn't do this? Or that it's not a problem?

© Programmers or respective owner

Related posts about mvc

Related posts about ruby-on-rails