Skip to content

Instantly share code, notes, and snippets.

@workmad3
Created September 28, 2015 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save workmad3/52733f7fefef7a0c3186 to your computer and use it in GitHub Desktop.
Save workmad3/52733f7fefef7a0c3186 to your computer and use it in GitHub Desktop.
class Project
has_many :project_blocks
has_many :upcoming_blocks, ->{ within(Date.current.beginning_of_week, 3.months.from_now.end_of_week) }, class_name: "ProjectBlock"
end
class ProjectBlock
def self.within(start_date, end_date)
timeframe = start_date..end_date
where(start_date: timeframe, end_date: timeframe)
end
end
class ProjectsController < ApplicationController
def index
@projects = Project.include(:upcoming_blocks)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment