On 12 October 2010 16:38, Leonel *.* <[email protected]> wrote:
>> Have you got a new line before the { ? It must all be on one line so
>> that ruby knows the { is the start of a block for the group_by call.
>> So the following all on one line:
>>
>> <% @appointments.group_by { |appointment|
>> appointment.start.strftime("%Y-%m-%d") }.each_pair do |start_date,
>> appointments| %>
>
> It's now all in one line
> --------------------------------------------------
> <% @appointments.group_by { |appointment|
> appointment.start.strftime("%Y-%d-%d") }.each_pair do |start_date,
> appointments| %>
The bit @appointments.group_by { |appointment|
appointment.start.strftime("%Y-%d-%d") } builds a hash where the key
part of each entry in the hash is the date and the value part is an
array of appointments for that date, then
.each_pair do |start_date, appointments| starts a block with
start_date containing the date and appointments containing the
appointments for that date. so you want then to say something like
<% appointments.each do |appointment| %> to iterate through the
appointments for that date. You are getting the error below because
appointment is not defined.
I have to say that this is quite a complex bit of code for a beginner
to get to grips with, but worth the effort to understand.
Colin
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.