views:

28

answers:

1

Hi

<%= user.name[0..9] %>

this gives abcdefghi

but I want it to be

if length is greater than 5 then abcde...

if less than 5 then abcde

+4  A: 

Rails has a built-in view helper for this:

<%= truncate(user.name, :length => 5) %>
John Topley
+1 - every time I start to code something on my own, it is already there.
Geoff Lanotte
Yeah, knowing what's already available is a big part of knowing Rails (or any framework/API).
John Topley