Ruby on Rails表单f.text

编程入门 行业动态 更新时间:2024-10-17 22:28:59
Ruby on Rails表单f.text_area包含额外的空格(Ruby on Rails form f.text_area contains additional spaces)

我在Rails中有一个非常平均的形式,通过blog_kit

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

在编辑博客文章时,正文突然包含其他空格(标记为_以显示):

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

因为textarea是空间感知的,它将显示空格。 在更新时,它们将添加到数据库中。

这些空间不在数据库中(在上面提到的错误更新之前)。 BlogPost.find(1)模型也不包含这些空格。

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

看起来有些逻辑在获取数据库之后但在以局部形式呈现之前添加了空格。 候选人是:

BlueCloth。 我启用了它,但找不到它将挂钩到加载过程的地方,并在textarea中呈现之前更改主体 HAML。 _form.html.rb部分尚未(尚)迁移到_form.haml,因此我假设haml远离此部分。 但它可能是麻烦的一部分?

我不知道从哪里开始寻找,所以任何提示都会非常受欢迎。

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:

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.

最满意答案

这是一个HAML问题。 请参见http://haml-lang.com/docs/yardoc/file.FAQ.html#q-preserve

在我的情况下,我的表单尚未转换为HAML(与您一样)但我已经转换了application.html.haml。 似乎HAML甚至对不是HAML格式的部分进行了一些缩进。

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.

更多推荐

本文发布于:2023-08-06 13:48:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1450287.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   Ruby   Rails   text

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!