Hyphenation in Rails

August 28 0 Comments Category: Coding, Posts

In web application development we often come across the problem of user entered information (for example comments) potentially containing veryveryverylongwords which spew outside their box and cause our designer’s beautiful layout to look awful (and horrid in IE6).

In a recent Rails app I was working on I came across this problem, luckily everywhere we had this problem was in content being rendered using the simple_format text helper. So with a little bit of research (thanks John Resig and Stackoverflow.com) I came up with this simple solution:

There one serious caveat to using this, it will cause problems if you allow any html or other markup in your comment (we do not).

There is also a javascript solution to this problem which may be more suited to you, Hyphenator.

Write a Comment

Commenter Gravatar