Rick Denatale wrote:
What do you EXPECT this to do?
Return an array.
Assuming that date is a Date then date+lookahead is also going to be a
Date.
Dates aren’t enumerable, and don’t have an each method.
True, Dates are not enumerable, but ranges are, and they respond to
each:
(date…date + look_ahead).class # Range
(date…date + look_ahead).respond_to? :each # true
If you want this to yield each appointment with a date look_ahead days
from date, then you probably want something like:
def lookup(date, look_ahead = 27)
return nil unless block_given?
appointments.find_all_by_date(date..date + look_ahead).each do
|appointment|
yield appointment
end
end
That achieves a similar effect, but I want my appointments to be grouped
by date. True there are other ways to group by date, but it makes my
views easier if I get a date and a collection of appointments on that
date. View:
<% @tattoo_artist.appointment_book.lookup(@date) do |date, appointments|
%>
<%= date.strftime('%A') %><%= ' (Today)' if
date.eql?(Date.today) %>
<%= date.strftime('%B %d, %Y') %>
<% appointments.each do |appointment| %>
<%= appointment.time %> with <%=
appointment.client.name %>
<%= appointment.description
%>
<% end %>
<% end %>
In other words, I want:
Date
Appointment for that date
Appointment for that date
Appointment for that date
Date
Appointment for that date
Even if I were to use SQL to group the results by date, I’d have to
perform extra manipulation to get the above effect. In this case I
prefer cleanliness over efficiency.