0

I'm creating a category menu on my app. I use the below code in my view to get unique categories to display.

<%= Listing.uniq.pluck(:category).each do |category| %>
   <%= link_to category, category_path(category: category) %>
<% end %>

If you look at the demo at mktdemo.herokuapp.com and click on the category dropdown in the navbar, you'll see the categories displayed. However, at the end, I get an array of all categories. Not sure why this is happening.

Moosa
  • 2,466
  • 5
  • 20
  • 40

1 Answers1

4

You should replace the first <%= with a <%-:

<%- Listing.uniq.pluck(:category).each do |category| %>
  <%= link_to category, category_path(category: category) %>
<% end %>

<%= causes the output to be printed, which in your case is an array.

fivedigit
  • 17,324
  • 6
  • 50
  • 58