RoR-带逗号分隔的类别链接

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了RoR-带逗号分隔的类别链接相关的知识,希望对你有一定的参考价值。

For separating a list of categories with a comma that are linked. There may be a better way. Leave a comment if you have a better way. This was the first way I found that worked.

This code increments the count 1 at a time. It applies the increment to the next loop of data.
  1. <% category_count = @post.categories.length %><% count = 1 %>
  2. <% @post.categories.each do |cat| %>
  3. <%= link_to cat.name, cat %><%= ", " unless category_count == count %><% count += 1 %>
  4. <% end %>

以上是关于RoR-带逗号分隔的类别链接的主要内容,如果未能解决你的问题,请参考以下文章

将逗号分隔属性另存为新记录

如何在Javascript中用逗号分隔的值匹配数组?

以逗号分隔的字符串查找目录列表,不带尾随逗号

匹配列中的逗号分隔值

T-SQL创建逗号分隔数组,同时保持父类别信息完整[重复]

confirm显示数组中的内容时,总是带一个逗号分隔的解决方法