gpt4 book ai didi

ruby-on-rails - haml 标签内的任何 Rails 代码都会在浏览器 html 标签内生成空白/空字符

转载 作者:行者123 更新时间:2023-11-28 17:47:21 29 4
gpt4 key购买 nike

每当 rails 变量等于 nil(或者实际上每当我使用 rails 代码(参见第 3 个代码示例))时,我的 html 中就会得到一串空字符。

new.html.haml

%h1.editable.editable_title_field{:contenteditable => 'true', :placeholder => "title"}
= @post_title //@post_title.present? returns false
%h4.editable.editable_subtitle_field{:contenteditable => 'true', :placeholder => "subtitle"}
= @post.subtitle
%p.editable.editable_intro_field{:contenteditable => 'true', :placeholder => "intro"}
= @post.intro

这导致:

enter image description here

我检查过,甚至:

%h1.editable.editable_title_field{:contenteditable => 'true', :placeholder => "title"}
- @post_title

和:

%h1.editable.editable_title_field{:contenteditable => 'true', :placeholder => "title"}
-

结果和附图一样

因为那些空字符 :empty css 选择器将元素视为非空元素并且不会附加 :before 中指定的内容

我如何摆脱我的 html 标签中的那些空字符?

编辑

此行为的截屏视频: http://quick.as/jqlaiorq

最佳答案

尝试使用 <%h1 的末尾行:

%h1.editable.editable_title_field{:contenteditable => 'true', :placeholder => "title"}<
= @post_title

参见 whitespace removal info在 HAML 文档中。

关于ruby-on-rails - haml 标签内的任何 Rails 代码都会在浏览器 html 标签内生成空白/空字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23025108/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com