Aleja V
0
Q:

how to find attendance by date range in rails?

<table>
  <thead>
    <tr>
      <th>Name</th>
      <th>Total Present</th>
      <th>Total Absent</th>
    </tr>
  </thead>
  <tbody>
    <% @manpowers.each do |manpower| %>
      <tr>
        <td><%= manpower.name %></td>
        <td><%= manpower.attendance.date_between(from_date, to_date).present.count %></td>
        <td><%= manpower.attendance.date_between(from_date, to_date).absent.count %></td>
      </tr>
    <% end %>
  </tbody>
</table>
0
class Attendance < ActiveRecord::Base
  scope :absent, where(status: 0)
  scope :present, where(status: 1)
  scope :date_between, -> (from_date, to_date) { where(attendance_date: from_date..to_date) }
end
0

New to Communities?

Join the community