开发者

RoR trim string

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜