Rails Categories下拉列表最后显示一个数组

时间:2014-08-30 19:29:32

标签: ruby-on-rails

我正在我的应用上创建一个类别菜单。我在视图中使用以下代码来显示要显示的唯一类别。

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

如果您在mktdemo.herokuapp.com查看演示并点击导航栏中的类别下拉列表,您会看到显示的类别。但是,最后,我得到了所有类别的数组。不知道为什么会这样。

1 个答案:

答案 0 :(得分:4)

您应该将第一个<%=替换为<%-

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

<%=会导致打印输出,在您的情况下是一个数组。