0

I want to construct a calendar full month view that looks like this (simplistically):

user        1   2   3   4   5   6   7   8   9   10   ...
user one            X           X       X
user two    X           X   X

Where 1..31 across the top is the calendar dates

This is sourced from the following models

user has_many leave_requests

leave_request belongs_to user
leave_request has_many leave_days

leave_day belongs_to leave_request

Currently, the only way I can get this to work is brute force it like this (this is pseudo-coded to save space - it's not the way I want to do it):

<%
@users = User.all
@users.each do |user|
%>
  <tr>
      <td><%= user.name %></td>
      <% (1..31).each do |day| %>
        <% user.leave_request.each do |lr| %>
          <% lr.leave_dates.each do |ld| %>
            <% if ld.date_requested == day %>
              <% text = day.date_requested %>
            <% else %>
              <% text = "" %>
            <% end %>
            <td><%= text %></td>
          <% end %>
        <% end %>
      <% end %>
  </tr>
<% end %>

I guess, what I'm really looking for is a way to map the dates from the leave_days table onto a calendar month. I don't mind a bit of complexity but this brute force approach just feels wrong

3
  • what is the function of a leave request?
    – davegson
    Jan 30, 2015 at 10:48
  • its the container for a single leave request for status/approvals etc. leave-dates holds the list of individual days in the request Jan 30, 2015 at 10:50
  • So it's like an invitation that one can accepts / reject?
    – davegson
    Jan 30, 2015 at 10:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.