Extra white spaces in a textarea element when using HAML and ERB
Sunday, March 8th, 2009I’m working on a legacy app that combines the use of HAML and erb markup templates for Ruby on Rails.
ROR deals with both templating markups seamlessly when used in the same application, but I noticed an issue when using a textarea element in a form on the page.
The problem:
I have a free text field that loads up an address. Every time the app would load the data from the database and display it in the textarea field, the resulting text would have extra spaces on second or third lines. Even if you deleted the spaces and saved the address, they would reappear next time I edited the field.
No styling, and no gsub action would fix the problem. Ultimately, it was caused because the template that rendered the form was an ERB template. In all other cases, the ERB templates rendered just fine, but when it came to textarea elements, it adds the white space. Normally, this isn’t a problem, but there seems to be a conflict when using HAML and ERB in the same app.
The solution:
It’s simple, convert the ERB template to HAML.
That’s it.
-Chris
