Skip to content

Instantly share code, notes, and snippets.

@fabianvelizok
Last active July 7, 2016 00:28
Show Gist options
  • Save fabianvelizok/fc3913b07d94180f244ef4d7fd88b4eb to your computer and use it in GitHub Desktop.
Save fabianvelizok/fc3913b07d94180f244ef4d7fd88b4eb to your computer and use it in GitHub Desktop.
# 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