Permalink
Browse files

[Event] fix upcoming scope.

Forgot that scopes need to be wrapped in lambda if they need to use a dynamic value each time (e.g., the reference to `Time.current`).

Also took into account the `end_at` time instead of just the `start_at` — primarily for events that span more than one day.
  • Loading branch information...
1 parent d50797c commit 128a726038bf24cbd50cc397eb510e2ed07a25a7 @grantneufeld committed Mar 11, 2012
Showing with 6 additions and 1 deletion.
  1. +6 −1 app/models/event.rb
View
@@ -37,7 +37,12 @@ class Event < ActiveRecord::Base
default_scope order('start_at')
scope :approved, where(:is_approved => true)
- scope :upcoming, where('start_at >= ?', Time.current.beginning_of_day)
+ scope :upcoming, lambda { # use a lambda so the time is reloaded each time upcoming is called
+ where(
+ 'start_at >= ? OR (end_at IS NOT NULL AND end_at >= ?)',
+ Time.current.beginning_of_day, Time.current.beginning_of_day
+ )
+ }
before_save :approve_if_authority
before_create :set_timezone

0 comments on commit 128a726

Please sign in to comment.