Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 366
nirmal Avatar asked Jan 25 '26 21:01

nirmal


1 Answers

Rails has a built-in view helper for this:

<%= truncate(user.name, :length => 5) %>
  • truncate helper API documentation
like image 55
John Topley Avatar answered Jan 27 '26 12:01

John Topley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!