开发者

rails view helper each with separator

I'm sure I saw a while back a rails helper method where .each in the view accepts a separator such as a comma.

So say I want:

- @re开发者_开发百科sults.each do |result| 
  = result.title

#to output
result 1, result 2, result 3

TIA


I think

@results.map(&:title).to_sentence

should do the job. See docu.


Not sure what you are refering to, but:

@results.collect { |r| r.title }.join( ',' )

should do what you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜