Last active
December 28, 2017 12:35
-
-
Save gmmcal/ab0452cf987cabef72d5a8bc9c09e0f8 to your computer and use it in GitHub Desktop.
Delete reviews from the last 24h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task :cleanup => :environment do | |
Review.over_24_hours.destroy_all | |
end | |
# You can call it as rake cleanup on terminal |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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