On 12 October 2010 18:59, Leonel . [email protected] wrote:
Please help 
Give us a chance! We have paying-work to do, you know! 
Right… first things first - your error:
16: <%= appointment.client.name %>
17: <%= appointment.service.name %>
18: <%= appointment.start.strftime(“%A %b %d %Y at %I:%M %p”)
%>
19: <%= link_to ‘Show’, appointment %>
One of the lovelies of Rails is how helpful the error messages are.
You’re being told that on line 16, you use a variable which is not
defined - and it even tells you its name: “appointment”.
The “each_pair” method is returning “start_date” and “appointments”
(and “appointments” is an Array of Appointment objects… so you need
to iterate that to draw the table row). Add an extra loop before you
render…
<% @appointments.group_by { |appointment|
appointment.start.strftime(“%Y-%d-%d”) }.each_pair do |start_date,
appointments| %>
<% appointments.each do |appointment| %>
<%= appointment.client.name %>
etc…
<% end %>
<% end %>
…it would probably be “better” to pass the appointments array to a
partial, and have that render the collection… but that’s a separate
issue - one step at a time 
This is all too confusing!! How can I understand what’s going on?
What don’t you understand?
The “@appointments.group_by.blah.blah” line? That’s just a load of
Ruby and Rails methods chained together… you could easily check out
each one in the API and read about what they do… but one of the ways
I like to find out what stuff like this is doing is play with it in
the console. Break it apart and run it one method at a time; see what
it returns, and make sure you understand why (with reference to the
API docs, and your books)
The separate commands are
@appointments # a collection of appointment objects
group_by { |appointment| appointment.start.strftime(“%Y-%d-%d”) } #
taking the @appointments collection and grouping it by the result of
evaluating each appointment’s start time as a string as “yyyy-mm-dd”.
The group_by method returns an ordered hash - see
http://api.rubyonrails.org/classes/Enumerable.html#method-i-group_by
each_pair do |start_date, appointments| # “each_pair” is just like
“each” but returns the key and value of a hash - so you have access to
the “key” (the date that appointments match) and the value (the set of
appointments from @appointments that have the same date as the key).
http://apidock.com/ruby/Hash/each_pair
I studied Simply Rails by Sitepoint and Agile Web
Development with Rails by Pragmatic Programmers. I just ordered the
pickaxe book last week and it’s on its way
You can’t have too many books 
I hope it’ll help me
understand because nothing makes sense to me right now.
Don’t despair - it’ll click in the end. I find that browsing the API
docs really helps me get a grip on the methods - just read through
bits when you have free time (man, I know how to party, don’t I? 
There does seem like there’s a lot to get to grips with when you’re
starting, but it does get easier, and at the end of the day, if you
write some code now, that may be a bit clunky, but works - when you
find methods that would make it work better/easier, you can always
refactor.