Hi i need to print out just the candidates where active is == 0 here is my code in the view.
I can print if active is yes or no.. But in the each do loop i just want to print the active candidates.
So how can i add the condition to my each do loop, thanks.  <% @candidates.each do |candidate| %>
    <div id="candidateper">
  <div class="avatth" ><div class="avat_min">
    <% if candidate.avatar.present? %>
       <%= link_to (image_tag candidate.avatar.url(:thumb)), (candidate_path(candidate))  %>
     <% else %>
     <%= link_to (image_tag ("espanol/playersample.png")), (candidate_path(candidate))  %>
     <% end %>
  </div></div>
      <div class="nameth"><%= candidate.name %></div>
      <div class="activeth"><%= candidate.active ? t('generales.yess') : t('generales.noo') %></div>
      <div class="generalth">
        <% if candidate.user.purchased_at.present? %>
          <%= candidate.user.purchase_defeated? ? t('generales.defeated') : t('generales.active') %>
        <% else %>
          <%=  t('generales.noo') %>
        <% end %>
      </div>
      <div class="actionsth"><%= link_to t('generales.show'), candidate_path(candidate) %>
      <% if current_user.user_type == 'admin' %>
      <%= link_to t('generales.delete'), candidate_path(candidate), method: :delete, data: { confirm: t('generales.delete_candidate_confirm') } %>
     <% end %>
    </div>
    </div>
  <% end %>
</div>
  <% end %>
I`ve tried this
no luck syntax error on all my ideas :P
If candidate.active is actually a boolean then you could say:
<% @candidates.reject(&:active).each do |candidate| %>
    ...
<% end %>
If @candidates is actually an ActiveRecord::Relation then you could probably say:
<% @candidates.where(:active => false).each do |candidate| %>
    ...
<% end %>
to avoid pulling a bunch of stuff out of the database when you don't want it.
If active is actually a number (inside the database and outside the database) then you could say:
<% @candidates.select(&:zero?).each do |candidate| %>
    ...
<% end %>
or
<% @candidates.where(:active => 0).each do |candidate| %>
    ...
<% end %>
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With