开发者

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.

s开发者_如何转开发cript/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:

  • BlueCloth. I have that enabled, but cannot find a place where it would hook into the load process, and alter the body before it is rendered in the textarea
  • HAML. The _form.html.rb partial is not (yet) migrated to _form.haml, so I assume haml stays away from this piece. But it might be part of the trouble?

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜