nirmal
nirmal

Reputation: 1121

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

Upvotes: 2

Views: 1945

Answers (1)

John Topley
John Topley

Reputation: 115322

Rails has a built-in view helper for this:

<%= truncate(user.name, :length => 5) %>

Upvotes: 9

Related Questions