Rails 用逗号和“and"连接字符串列表.在最后一次之前 [英] Rails join a list of strings with commas and "and" before the last

查看:34
本文介绍了Rails 用逗号和“and"连接字符串列表.在最后一次之前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有标准的 Rails 助手可以将诸如 ["apple", "banana", "pear"] 之类的字符串数组转换为 "apple,banana, and pear"代码> 用于插入句子?

Is there a standard rails helper that converts an array of strings like ["apple", "banana", "pear"] into "apple, banana, and pear" for inserting into a sentence?

推荐答案

是的,to_sentence 应该很好用.

Yeah to_sentence ought to work nicely.

http://apidock.com/rails/Array/to_sentence

这篇关于Rails 用逗号和“and"连接字符串列表.在最后一次之前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆