I assume that you really want to keep the range in your model, not the value within the range. (If you want to do the latter, validation will be your answer).
So the range. In the model. You have two options, each of which is pretty decent.
Option 1: Create a column ( range_column) of type text. Pass a Ruby range object to a column, for example @my_model_object.range_column = (50..100). Tell Rails to serialize your range as follows:
class MyModel < ActiveRecord::Base
serialize :range_column
end
Now Rails will automatically convert your range to YAML for storing the database and convert it back to a range object when it retrieves the record again. Not much easier than that!
Option 2: Create two columns ( range_startand range_end) the type 'integer'. Set up something in your model as follows:
class MyModel < ActiveRecord::Base
def range=(rstart, rend)
self.range_start = rstart
self.range_end = rend
end
def range
(range_start..range_end)
end
end
The first option is simpler (and, in my opinion, better), and the second gives you a little flexibility out of the box if you don't want to use a Ruby range object (though, why would you?).