ruby-on-rails – rails-显示文本字段中的certian字符数
发布时间:2020-12-17 04:22:23 所属栏目:百科 来源:网络整理
导读:我正在运行一个rails项目,我正在显示一个通常太长的文本字段.如果有任何我可以调用的东西只在视图页面上显示20个单词或120个字符? 解决方法 您可能对TextHelper的 truncate功能感兴趣: truncate("Once upon a time in a world far far away") # = Once upo
我正在运行一个rails项目,我正在显示一个通常太长的文本字段.如果有任何我可以调用的东西只在视图页面上显示20个单词或120个字符?
解决方法
您可能对TextHelper的
truncate功能感兴趣:
truncate("Once upon a time in a world far far away") # => Once upon a time in a world f... truncate("Once upon a time in a world far far away",:length => 14) # => Once upon a... truncate("And they found that many people were sleeping better.",:length => 25,"(clipped)") # => And they found that many (clipped) truncate("And they found that many people were sleeping better.",:omission => "... (continued)",:length => 15) # => And they found... (continued) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |