Embarrassingly, I must admit that I have never understood models. I
am hoping that with this post I can clear up a basic question that
will allow me to get a toe-hold into understanding models. The basic
question is this:
Do we only use models with databases or do they have other uses?
Models descend from ActiveRecord::Base. That certainly gives rise to
a notion that models are used exclusively with databases. However, I
have read plenty of chatter encouraging me to move code out of the
controller and into the model.
At the moment, I happen to be dealing with a perfect example. In a
user's profile I store an integer named 'flags'. The integer is a
decimal representation of a set of binary flags that correspond to
various yes/no configuration selections that the user has made. I
have written a very short method that will accept 2 arguments, a
user's flags integer and the weight of a specific flag. The method
returns true or false depending on whether the specific flag is set in
the given flags integer. The method has absolutely nothing to do with
a database. The question is: Where do I put this method? From the
description that I have given I think that it is clear that this
method is back-room, heavy-duty, number-crunching stuff (to use terms
that I have seen in my reading). So, does it go in the model? If so,
how do I access it from other places?
Thanks very much for any input.