Skip to content

Instantly share code, notes, and snippets.

@ktec
Last active June 27, 2016 14:39
Show Gist options
  • Save ktec/357c217630b37b057ab252eb3e80783e to your computer and use it in GitHub Desktop.
Save ktec/357c217630b37b057ab252eb3e80783e to your computer and use it in GitHub Desktop.

Revisions

  1. ktec revised this gist Jun 27, 2016. No changes.
  2. ktec created this gist Jun 27, 2016.
    12 changes: 12 additions & 0 deletions arel_cast_datetime_as_as.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    # frozen_string_literal: true
    class Things < ApplicationRecord
    scope :filter_after_date, -> (date) {
    where(created_at_as_date.gteq(date))
    }
    scope :filter_before_date, -> (date) {
    where(created_at_as_date.lteq(date))
    }
    def self.created_at_as_date
    Arel::Nodes::NamedFunction.new "DATE", [ arel_table[:created_at] ]
    end
    end