开发者

rails view helper each with separator

开发者 https://www.devze.com 2023-01-11 07:32 出处:网络
I\'m sure I saw a while back a rails helper method where .each in the view accepts a separator such as a comma.

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

精彩评论

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