Wednesday, June 09, 2010

Rails 2.3.8 + HTML strings.

Be careful with doing concatenating inside of ERB views with Rails 2.3.8.

This recently broke an app that concat'd (via '+') two strings full of HTML. Before you ask, no, I don't know why anyone would do that in a view of all places.

The quick fix was to call String#html_safe on the second string (I didn't check to see if there was any other solution since the fix was urgent).

Without String#html_safe, what ended up happening was that the 2nd string's HTML was escaped -- thus breaking the app in a few places.

No comments: