menu and menu item categories

This commit is contained in:
Min Zeya Phyo
2017-04-15 17:33:45 +06:30
parent 355f4fadb0
commit 63c5c97f24
24 changed files with 303 additions and 39 deletions

View File

@@ -3,4 +3,23 @@ class Menu < ApplicationRecord
validates_presence_of :name,:is_active, :valid_days, :valid_time_from, :valid_time_to
#Default Scope to pull the active version only
default_scope { where(is_active: true).order("created_at desc") }
def self.current_menu
today = DateTime.now
day_of_week = today.wday
menus = Menu.where("is_active = true and '#{today.strftime("%H:%M")}' between TIME(valid_time_from) and TIME(valid_time_to)")
current_menu = nil
#Loop through the menu which is valid days - get the first menu out and return result
menus.each do |menu|
if menu.valid_days.include?(day_of_week.to_s)
current_menu = menu
break
end
end
return current_menu
end
end