Make poll scope more readable
This was the only place where we used the `? <= field` format; we use the `field >= ?` format everywhere else. We're also adding a variable to make it easier to understand that the value is the same in both cases and to make the line shorter ;).
This commit is contained in:
@@ -42,7 +42,7 @@ class Poll < ApplicationRecord
|
|||||||
accepts_nested_attributes_for :questions, reject_if: :all_blank, allow_destroy: true
|
accepts_nested_attributes_for :questions, reject_if: :all_blank, allow_destroy: true
|
||||||
|
|
||||||
scope :for, ->(element) { where(related: element) }
|
scope :for, ->(element) { where(related: element) }
|
||||||
scope :current, -> { where("starts_at <= ? and ? <= ends_at", Date.current.beginning_of_day, Date.current.beginning_of_day) }
|
scope :current, -> { where("starts_at <= :time and ends_at >= :time", time: Date.current.beginning_of_day) }
|
||||||
scope :expired, -> { where("ends_at < ?", Date.current.beginning_of_day) }
|
scope :expired, -> { where("ends_at < ?", Date.current.beginning_of_day) }
|
||||||
scope :recounting, -> { where(ends_at: (Date.current.beginning_of_day - RECOUNT_DURATION)...Date.current.beginning_of_day) }
|
scope :recounting, -> { where(ends_at: (Date.current.beginning_of_day - RECOUNT_DURATION)...Date.current.beginning_of_day) }
|
||||||
scope :published, -> { where(published: true) }
|
scope :published, -> { where(published: true) }
|
||||||
|
|||||||
Reference in New Issue
Block a user