I have two models, CheckIn and Consumer. The idea is that consumers can check in any number of times. I want to define a function in the Consumer model that allows me to return the top x_number of consumers who have the most CheckIns, sorted from highest to lowest number of CheckIns.
class Consumer < ActiveRecord::Base
has_many :check_ins, dependent: :destroy
def with_most_checkins( num_to_show )
# ???
end
end
class CheckIn < ActiveRecord::Base
belongs_to :consumer
end