ruby-on-railserbform-helpersbluecloth

Ruby on Rails form f.text_area contains additional spaces


I have a quite average form in Rails, trough blog_kit

<% form_for(@blog_post, :html => { :multipart => true }) do |f| %>\
  ... other code
  <%= f.text_area :body %>
  <%= debug(@blog_post) %>

When editing a blog-post, the body suddenly contains additional spaces (marked as _ to visualise):

...sit amet eleifend diam imperdiet pharetra.
__ 
__## FOO?
__Morbi nec

Because a textarea is space-aware, it will show the spaces. On update, they are added to the database.

These spaces are not in the database (before the erronous update mentioned above, that is). Nor does the model BlogPost.find(1) contain these spaces.

script/console » b = BlogPost.find(1)
» puts b.body
...sit amet eleifend diam imperdiet pharetra.

## FOO?
Morbi nec

It appears some logic adds the spaces, after fetching the the database, but before rendering in the form partial. Candidates are:

I do not know where to start looking, so any hints would be very welcome.


Solution

  • This is a HAML issue. See http://haml-lang.com/docs/yardoc/file.FAQ.html#q-preserve

    In my case my form was not yet converted to HAML (like you) but I had the application.html.haml converted. It seems that HAML does some indenting even to partials that are not in HAML format.