Answers for "how to find attendance by date range in rails?"

0

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>
Posted by: Guest on August-04-2020
0

how to find attendance by date range in rails?

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
Posted by: Guest on August-04-2020

Browse Popular Code Answers by Language