Skip to content

Instantly share code, notes, and snippets.

@mrgenixus
Last active February 17, 2016 04:30
Show Gist options
  • Select an option

  • Save mrgenixus/aa33d28f445e80c55091 to your computer and use it in GitHub Desktop.

Select an option

Save mrgenixus/aa33d28f445e80c55091 to your computer and use it in GitHub Desktop.
Extracted from ShoppingList#list_items as refactor
scope :without_removed, -> { where(arel_table[:removed].eq(nil).or(arel_table[:removed].eq(0))) }
scope :only_removed, -> { where(arel_table[:removed].not_eq(nil)).where(arel_table[:removed].not_eq(0)) }
def self.date_range start_date, end_date
includes(:event).
where(Event.arel_table[:event].gteq(start_date)).
where(Event.arel_table[:event].lteq(end_date))
end
list_items = ShoppingListItems.where(user_id: current_user.id).include(:ingredients)
list_items = list_items.date_range(start_date, end_date)
list_items = list_items.without_removed if options[:hide_removed]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment