I have a Cover model, in the cover.rb
file, I also define a method called size
which returns an integer representing 'small, intermediate, large'.
My question is how can I retrieve all the small/intermediate/large covers?
My guess is to use scope
, but I cannot figure out how to pass the size
method as a condition.
class Cover < ActiveRecord::Base
attr_accessible :length, :width
# TODO
scope :small
scope :intermediate
scope :large
# I have simplified the method for clarity.
# 0 - small; 1 - intermediate; 2 - large
def size
std_length = std_width = 15
if length < std_length && width < std_width
0
elsif length > std_length && width > std_width
2
else
1
end
end
end