Matthew Williams
2008-Jan-30 13:29 UTC
Iterating through hash to line up dates correctly in a table
I have a simple table right now: <table border=1> <tr> <td>OBS Number</td> <% for week in @week_endings%> <td><%=week.week_ending%></td> <%end%> </tr> <%@results.keys.each do |result| %> <tr> <td><%=result%></td> <% @results[result].each do |test| %> <td>Date: <%= test[0] %> - Hours: <%= test[1] %></td> <%end%> </tr> <%end%> </table> @week_endings contains dates that are applicable to my @results object which is a nested hash of ID''s containing dates which have associated values. After I setup my header which would look like: OBS Number 01-04-2008 01-11-2008 I would like to iterate through my hash and where the data applicable, place it in the table in the column containing the date it pertains to. So a row would look like the following with the hash: {"25",{"01-04-2008","5.0"},{"01-11-2008","10.0"}} {"30",{"01-11-2008","10.0"}} OBS Number 01-04-2008 01-11-2008 25 5.0 10.0 30 0.0 10.0 Where I''m building my rows using my hash with the following: <%@results.keys.each do |result| %> <tr> <td><%=result%></td> <% @results[result].each do |test| %> <td>Date: <%= test[0] %> - Hours: <%= test[1] %></td> <%end%> </tr> <%end%>[/code] I would think I could use my @week_endings object... So something along the lines of for result for week if result.week == week <td>value else <td>0 end end An value for a day for given ID may not exist. So if could have a value for the 11th but not the 4th so I need to skip by the 4th by putting a 0 in the field and move on to the 11th and insert that value. But when I tried to code that my values weren''t printing correctly. Any thoughts would be appreciated, sorry if this comes off as confusing, I tried to make it sound as simple as possible :) I can always elaborate if needed. Thanks! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---