Last active
July 7, 2016 00:28
-
-
Save fabianvelizok/fc3913b07d94180f244ef4d7fd88b4eb 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
# Option 1 | |
pharmacies = [] | |
Pharmacy.all.each do |pharmacy| | |
if pharmacy.recurrent_days.present? | |
recurrent_days = pharmacy.recurrent_days.split(',').map { |day| day.to_i } | |
pharmacies << pharmacy if recurrent_days.include?(Time.now.wday) | |
end | |
end | |
# Option 2 | |
scope :todays, -> (q) { where([ "recurrent_days LIKE ?", "%#{q}%" ]) } | |
pharmacies = Pharmacy.todays(Time.now.wday) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment