Skip to content

Commit

Permalink
moved query to scope
Browse files Browse the repository at this point in the history
  • Loading branch information
Glenn Harmon committed Nov 9, 2017
1 parent fdb665e commit 66cd80a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/models/meeting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ class Meeting < ActiveRecord::Base

attr_accessor :crb_times

scope :future_meetings, -> { where(["DATE(time) >= ?", Date.today]).order('time ASC') }
scope :lecture, -> { where(["format = ?", "Lecture"]) }
scope :current_month_crb, -> { where(["DATE(time) >? AND DATE(time)<?", Time.now.beginning_of_month, Time.now.end_of_month]).order('time ASC').limit(1) }
def self.add_speaker_to_next_meeting(name, title, url)
find_or_create_next_date.speakers.create!({name: name, title:title, url: url})
end

def self.find_or_create_next_date
@next_crb = Meeting.where(["DATE(time) >= ?", Date.today]).order('time ASC').first
@next_crb = future_meetings.first
if @next_crb.blank?
if Meeting.current_month_crb.blank?
if current_month_crb.blank?
next_month = 0
else
next_month = 1
Expand All @@ -26,7 +27,7 @@ def self.find_or_create_next_date
e = curr_time.end_of_month
crb_time = (s..e).select{|d| d.wday == 1}[2] + 18.5.hours

Meeting.find_or_create_by(time: crb_time)
find_or_create_by(time: crb_time)
else
@next_crb
end
Expand Down

0 comments on commit 66cd80a

Please sign in to comment.