Categories

<% @categories.each do |cat| %> <% cat_product_count = cat.products.count %> <%end%>
Name Product count Sort index
<%= cat.name %><%= cat_product_count %> <%= cat.sortorder %>
<%# Put the edit link inside form just for formatting so they are one same line %> <%= form_tag([:admin, cat], method: :delete) do %> <%= link_to 'Edit', edit_admin_category_path(cat), class: "btn btn-primary btn-sm" %> <%= submit_tag("Delete", class: "btn btn-danger btn-sm") if cat_product_count == 0 %> <%# Tried using 'disabled' class to prevent delete when products exist in category but it would hover a circle crossed out and clicking would still submit the delete action. disabled css class can be used on links that are displayed as buttons to prevent clicking. but disabled css class shouldn't be used on inputs like submit button because it appears disabled but still allows clicking.%> <% end %>

<%= link_to 'Add category', new_admin_category_path, class: "btn btn-primary" %>