Last active
September 25, 2020 12:01
-
-
Save spencerldixon/900bd759d89fdd32330c60ad3938f3e5 to your computer and use it in GitHub Desktop.
Useful Scopes
This file contains 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
# Recent things with optional period parameter | |
scope :recent, ->(period = 30.days) { where("created_at >= ?", period.ago.beginning_of_day) } | |
# With Active::Text :notes field | |
scope :with_notes, -> { left_joins(:rich_text_notes).where('action_text_rich_texts.id is NULL') } | |
# Between two optional dates (uses keyword arguments for optional params) | |
scope :between, ->(from: 30.days.ago, to: Date.current) { where(created_at: from.beginning_of_day..to.end_of_day) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment