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

我正在运行一个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)

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...