当前位置: 动力学知识库 > 问答 > 编程问答 >

Any rails code inside haml tags generates blank/empty characters inside browsers html tags

问题描述:

Whenever a rails variable equals nil (or actually whenever i use rails code (see 3rd code sample)) i get a string of empty characters in my 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

this results in:

i checked, and even:

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

- @post_title

and:

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

-

ends up the same as in attached image

because of those empty characters :empty css selector treats the element as if it was not empty and doesnt append content specified in :before

how do i get rid of those empty characters inside my html tags?

EDIT

screencast of this behavior:

http://quick.as/jqlaiorq

网友答案:

Try it with a < on the end of the %h1 line:

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

See the whitespace removal info in the HAML documentation.

分享给朋友:
您可能感兴趣的文章:
随机阅读: