Created
June 7, 2013 03:09
-
-
Save alnutile/5726820 to your computer and use it in GitHub Desktop.
Model and Controller after moving the query logic into the model and using scopes
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
@speaker_requests_upcoming = SpeakerRequest.published.content(search).date_range(date_start, date_end) | |
@speaker_requests_upcoming = @speaker_requests_upcoming.paginate(page: params[:page], :order => "date ASC") |
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
scope :published, -> { where published: true } | |
scope :content, ->(searched) { where(["content LIKE ?", "%#{searched}%"]) } | |
scope :date_range, ->(start_date, end_date) { | |
where("date between ? and ?", start_date, end_date) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not bad. Don't forget that you can add order as a scope also.