开发者

RoR trim string

开发者 https://www.devze.com 2023-01-07 11:12 出处:网络
this gives 开发者_运维技巧abcdefghi but I want it to be if length is greater than 5 then abcde... if less than 5 then

this gives 开发者_运维技巧abcdefghi

but I want it to be

if length is greater than 5 then abcde...

if less than 5 then abcde


Rails has a built-in view helper for this:

<%= truncate(user.name, :length => 5) %>
  • truncate helper API documentation
0

精彩评论

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