Created
September 28, 2015 17:19
-
-
Save workmad3/52733f7fefef7a0c3186 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProjectBlock | |
def self.within(start_date, end_date) | |
timeframe = start_date..end_date | |
where(start_date: timeframe, end_date: timeframe) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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