Skip to content

Instantly share code, notes, and snippets.

@jmercedes
Last active December 13, 2015 17:38
Show Gist options
  • Save jmercedes/4949128 to your computer and use it in GitHub Desktop.
Save jmercedes/4949128 to your computer and use it in GitHub Desktop.
<%= f.select :atime, @time_options %>
undefined method `empty?' for nil:NilClass
def self.time_options
start_of_day = Time.zone.now.beginning_of_day
start_time = start_of_day + 9.hours
end_time = start_of_day + 17.hours
lunch_start = start_of_day + 13.hours
lunch_end = start_of_day + 14.hours + 30.minutes
times = []
until start_time > end_time
start_time = (start_time + 30.minutes)
unless start_time >= lunch_start && start_time < lunch_end
times << start_time
end
end
times.map{|t| [t.strftime("%I:%M%p").downcase, t.to_s(:db)] }
end
def new
@time_options = Appointment.time_options
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment