Skip to content
Browse files

Include log entry list on index page

  • Loading branch information...
1 parent 4eb6bc2 commit 457c314321c5ef58b3958d823395ea6e810710d8 @nickh committed Aug 29, 2008
Showing with 46 additions and 1 deletion.
  1. +22 −0 app/helpers/log_entry_helper.rb
  2. +24 −1 app/views/log_entries/index.html.erb
View
22 app/helpers/log_entry_helper.rb
@@ -0,0 +1,22 @@
+module LogEntryHelper
+ def trip_time(entry)
+ # strftime templates for displaying date/time info
+ date_str = '%m-%d-%y'
+ time_str = '%H:%M'
+ dt_str = date_str + ' ' + time_str
+
+ if entry.departed_at
+ start_str = entry.departed_at.strftime(dt_str)
+ if entry.arrived_at
+ depart_date = Date.parse(entry.departed_at.to_s)
+ arrive_date = Date.parse(entry.arrived_at.to_s)
+ end_str = entry.arrived_at.strftime(depart_date == arrive_date ? time_str : dt_str)
+ start_str + '-' + end_str
+ else
+ 'Departed at ' + start_str
+ end
+ else
+ 'Preparing to leave'
+ end
+ end
+end
View
25 app/views/log_entries/index.html.erb
@@ -1 +1,24 @@
-These are log entries
+<div id="log-entries">
+ <div id="log-entries-nav">
+ <%= link_to 'Add a log entry', new_log_entry_url %>
+ </div>
+ <table class="log-entries">
+ <tr>
+ <th>Trip Time</th>
+ <th>Origin/Dest</th>
+ <th>Notes</th>
+ </tr>
+ <% @entries.each do |entry| %>
+ <tr>
+ <td><%= trip_time(entry) %></td>
+ <td>
+ <%= entry.origin %>
+ <% if entry.destination && !entry.destination.blank? && entry.destination != entry.origin %>
+ to <%= entry.destination %>
+ <% end %>
+ </td>
+ <td><%= entry.notes %></td>
+ </tr>
+ <% end %>
+ </table>
+</div>

0 comments on commit 457c314

Please sign in to comment.
Something went wrong with that request. Please try again.