Rails separate array items with comma inside partial

前端 未结 1 1256
小蘑菇
小蘑菇 2021-01-16 13:12

What is the most elegant way in Rails to create a comma-separated list inside a partial?

I\'ve just recently discovered that you can use partials to iterate through

相关标签:
1条回答
  • 2021-01-16 13:33

    Ruby's join method won't add the separator character if there is only a single element in the array.

    You should be able to do the following for a list of any size:

    @dvd.director.map(&:director).join(", ")
    
    0 讨论(0)
提交回复
热议问题