我在work
和category
模型之间存在双向多对多的关系。当我在我的work#index
HTML:
<% @works.each do |work| %>
<article class="work-item" data-project="<%= work.id %>">
<header class="w-article-title ">
<%=raw work.svg %>
<h1 class="article-name"><%= work.name %></h1>
<ul class="categories-total n-visible">
<li><%= work.categories.pluck(:name) %></li>
</ul>
</header>
</a>
</article>
<% end %>
它最终会返回一个字符串数组,如:
["Visual Design", "Strategy + UX", "UxD"]
如何进行布局显示:
答案 0 :(得分:3)
<ul class="categories-total n-visible">
<% work.categories.pluck(:name).each do |n| %>
<li><%= n %></li>
<% end %>
</ul>