ruby-on-rails – rails-显示文本字段中的certian字符数

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – rails-显示文本字段中的certian字符数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在运行一个rails项目,我正在显示一个通常太长的文本字段.如果有任何我可以调用的东西只在视图页面显示20个单词或120个字符?

解决方法

@H_403_5@ 您可能对TextHelper的 truncate功能感兴趣:
  1. truncate("Once upon a time in a world far far away")
  2. # => Once upon a time in a world f...
  3.  
  4. truncate("Once upon a time in a world far far away",:length => 14)
  5. # => Once upon a...
  6.  
  7. truncate("And they found that many people were sleeping better.",:length => 25,"(clipped)")
  8. # => And they found that many (clipped)
  9.  
  10. truncate("And they found that many people were sleeping better.",:omission => "... (continued)",:length => 15)
  11. # => And they found... (continued)

猜你在找的Ruby相关文章