Home Display products "if" part of category

# Display products "if" part of category

Jake
1#
Jake Published in 2018-01-12 19:26:10Z
 I have a product page with 4 different category tabs on it. A created product can only belong to one of the 4 categories/tabs on the page. These categories are all displayed on the top of the tab-pane via images side-by-side. What needs to be added to the <% @packs.each do |pack| %> section to load the products "if" they are of that category, thank you! This is an example of one of the tab Category selection links... 

Samples

<%= image_tag("btn_Category_1.png", :alt => "Category one", class: "image-pad center") %>
 Followed by its corresponding tab, linked to the selector above... 
<% @packs.each do |pack| %>
<%= link_to pack_path(pack) do %> <%= image_tag("#{pack.art_link}", :alt => "Product Image", :width => 333, :height => 333, class: "feat-img") %> <% end %>
<% end %>

Josh Brody
2#
Josh Brody Reply to 2018-01-12 19:30:24Z
 You can do it a few different ways. Here's two: In your controller, @packs = @packs.group_by { |pack| pack.category.name } should result in something like {'samplePillars' => [Pack, Pack]} In your view @packs.select { |pack| pack.category.name == 'samplePillars' }.each do ... end will return an array of @packs where the category.name is samplePillars There are more idiomatic ways of doing this but for the sake of getting started, these two are fine.
 You need to login account before you can post.
Processed in 0.328532 second(s) , Gzip On .