Tuesday, March 18, 2014

Truncating text or string in Ruby

Hi Guys - Today I was working on a small issue where I had to add some client side validation.

The fix was to add limit to the number of chars in a text area. The fix is as easy as adding 'maxlength=n' attribute.

But this can be circumvented easily in the client side. So what ?

In the server side, are we going to throw an error and raise an exception that the text is too long ?

Well another way is to truncate this text.

In ruby, simply do this -

This will simply truncate the text


No comments:

Post a Comment