I got to here myself, but it's not right ! I think it's close though and
I find this syntax easier to read.
def availability
@bookings = Booking.find(:all)
for booking in @bookings do
bookingfirstday = booking.from.to_date
bookinglastday = booking.to.to_date
@BookedDays = (bookingfirstday..bookinglastday).map
end
end
Can you explain why it's wrong ?
The result is that I @BookedDays only gets set to the last evaluated
booking (I think).
I will try your way though, thanks. (I'd like to get my way working also
if poss)?
Is the loop rewriting @BookedDays each time around rather than adding to
it?
I got to here myself, but it's not right ! I think it's close though and
I find this syntax easier to read.
def availability
@bookings = Booking.find(:all)
for booking in @bookings do
bookingfirstday = booking.from.to_date
bookinglastday = booking.to.to_date
@BookedDays = (bookingfirstday..bookinglastday).map
end
end
Can you explain why it's wrong ?
The result is that I @BookedDays only gets set to the last evaluated
booking (I think).
I will try your way though, thanks. (I'd like to get my way working also
if poss)?
Is the loop rewriting @BookedDays each time around rather than adding to
it?
ta
There are a couple problems. The first is that, yes, @BookedDays is
being rewritten, not appended to. You need to initialize the array
before the loop starts (@BookedDays = ) and use the += method to
append to it. Also, you should renamed that variable to @booked_days.
You can do this with a for-loop, but I suggest getting used to the
closured-oriented methods in Enumerable and Array. Your code will be
much more concise and expressive.
Thanks that's very clear and helpful, I'll try and use the more concise
method.
It's working for me and I understand why my version wasn't.
Maybe my brain is squished but I've done the hard thing and now this
next more simple loop is causing me problems in my view. I wish to show
12 calendars from the current month to 12 months on.
So I know how to display one....<working>
<%= calendar(:year => 2009, :month => 1) do |d|
if @BookedDays.include?(d)
[d.mday, {:class => "specialDay"}]
else
[d.mday, {:class => "normalDay"}]
end
end
%>
How do I display twelve of em...I know this is uber easy but I can't get
it to work.
I firgure something like what follows is useful but I cant get the loop
within the loop working in the view.
Small critique here on your code style. @BookedDays doesn't really
follow Ruby on Rails conventions. Camel-case should only be used by
class/module definitions and references. @booked_days is the
convention that Rails encourages.
This might be something that you've decided based on a personal or
team preference, but in case you're not attached to it, following
Rails conventions will make your life and anybody else that later
works on a project.. a little easier.