mardi 7 janvier 2020

How to select data from multiple model in rails

i have three model project_manager, project_director, and human_resource each has a status Boolean field how can i print some thing in rails if Boolean value of these three model is true. currently i am accessing data from model by doing this-

            <% if project_site.project_managers.empty? %>
              <td class="pending fi-eye"><%= " Pending" %></td>
            <% else %>
              <% project_site.project_managers.each do |project_manager| %>
                <% if project_manager.status == false %>
                  <td class="rejected fi-x"><%= ' Rejected' %></td>
                <% elsif project_manager.status == true %>
                  <td class="approved fi-check"><%= " Approved" %></td>
                <% end %>
              <% end %>
            <% end %>

            <% if project_site.project_directors.empty? %>
              <td class="pending fi-eye"><%= " Pending" %></td>
            <% else %>
              <% project_site.project_directors.each do |project_director| %>
                <% if project_director.status == false %>
                  <td class="rejected fi-x"><%= ' Rejected' %></td>
                <% elsif project_director.status == true %>
                  <td class="approved fi-check"><%= " Approved" %></td>
                <% end %>
              <% end %>
            <% end %>

            <% if project_site.human_resources.empty? %>
              <td class="pending fi-eye"><%= " Pending" %></td>
            <% else %>
              <% project_site.human_resources.each do |human_resource| %>
                <% if human_resource.status == false %>
                  <td class="rejected fi-x"><%= ' Rejected' %></td>
                <% elsif human_resource.status == true %>
                  <td class="approved fi-check"><%= " Approved" %></td>
                <% end %>
              <% end %>
            <% end %>

i want to print approved if all these three model status value is true how can i do that in rails?

Aucun commentaire:

Enregistrer un commentaire