I have been following a few Rails Beginner tutorials and have been
able to get a good simple app up where I have a bunch of servers and I
am tracking the number of users on those servers every week.
I have been able to get the app running so that I can view the user
counts for a Server - looks like this, which is displayed via the
server model's show.rhtml:
Server Name: EastWS2003
So far so good, but rather than have that usercount table store the
date of that report I have a third table that consists of an id field
and a field called "weekending", which stores that actual date.
The usercount table has a field called reportdate_id which points to
the reportdate table.
The result I want is to see something like this:
However I can't figure out how to code this into the show.rhtml to
pull in the actual date from the reportdate table. Here is the
original code from show.rhtml that displays the user count.
<% if @server.has_usercounts? %>
<% for usercount in @server.usercounts %>
<td><%= usercount.reportdate.weekending.strftime('%m/%d/%Y') %></td>
<td><%= usercount.users %></td>
<% end %>
<% end %>
Can anyone point me in the right direction?
Assuming that your models reflect the associations that you implied (and that I'm interpreting them right).
set_table_name 'reportdate' # because you imply it's not plural
But if this is a common thing, I'd suggest you also have a method:
Define your own format (in your environment.rb perhaps)
Time::DATE_FORMATS[:stoop] = '%m/%d/%Y'
and in your view say:
<td><%= usercount.weekending.to_s(:stoop) %></td>
Of course, you can replace :stoop with :mdy or anything else that suits you.
Rob Biedenharn http://agileconsultingllc.com