Skip to content

Instantly share code, notes, and snippets.

@gmmcal
Last active December 28, 2017 12:35
Show Gist options
  • Save gmmcal/ab0452cf987cabef72d5a8bc9c09e0f8 to your computer and use it in GitHub Desktop.
Save gmmcal/ab0452cf987cabef72d5a8bc9c09e0f8 to your computer and use it in GitHub Desktop.
Delete reviews from the last 24h
task :cleanup => :environment do
Review.over_24_hours.destroy_all
end
# You can call it as rake cleanup on terminal
class Review < ActiveRecord::Base
scope :last_24_hours, -> { where('created_at >= ?', Time.now - 1.day) }
scope :over_24_hours, -> { where('created_at < ?', Time.now - 1.day) }
# The methods below do the same as scope above
# def self.last_24_hours
# where('created_at >= ?', Time.now - 1.day)
# end
# def self.over_24_hours
# where('created_at < ?', Time.now - 1.day)
# end
end
class ReviewsController < ApplicationController
def index
@reviews = Review.last_24_hours
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment