I"m trying to display the best 3 Recipes from the last 7 days. The best is dependant on the amount of votes it has using the acts_as_votable gem but i have not created a cache. current user.rb, limits to the last 7 days
def featuredfeed
Recipe.where('created_at >= ?', Time.zone.now - 1.week)
end
recipe.rb
class Recipe < ActiveRecord::Base
belongs_to :user
acts_as_votable
....
default_scope -> { order(created_at: :desc) }
end
the votes table is ordered
id, votable_id, votable_type, voter_id, voter_type, vote_flag, vote_scope, vote_weight, created_at, updated_at
The votable_id is the id of the recipe which needs to be counted for the number of times it has been upvoted
Aucun commentaire:
Enregistrer un commentaire