I am creating a simple appointment keeper in Rails 4, and I need to create an array of times for the user to choose between a min/max. The user can also choose if they are creating a 30 or 60 min appointment.
I tried to create the array like this
def time_range
return [] if time_start.blank? || time_end.blank?
(time_start.to_time .. time_end.to_time).to_a
end
but I keep getting the error
can't iterate from Time
I don't know how I could break this out into increments, either.
I'm just showing them as a list
ul.list-unstyled
- @meeting.time_range.each do |calendar_time|
li
= calendar_time
Make use of step
(Time.now.to_i..1.day.from_now.to_i).step(30.minutes).each do |time|
puts Time.at(time)
end
So the method will be
def time_range
return [] if time_start.blank? || time_end.blank?
(time_start.to_time.to_i..time_end.to_time.to_i)
end
And you can use it as
ul.list-unstyled
- @meeting.time_range.step(30.minutes).each do |calendar_time|
li
= Time.at(calendar_time)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With