html - 输出的 HTML 中的 Rails 缩进会发生什么情况?

标签 html ruby-on-rails indentation

我正在为 TextMate 中的 Rails View 编写代码(使用 2 空格缩进标准)。每当我查看我的网页的输出(查看源代码)时,HTML 括号总是看起来奇怪地缩进。例如,我的 application.html.erb 看起来像这样:

<!DOCTYPE html>
<html>
<head>
  <title>Rainleader</title>
  <%= stylesheet_link_tag :all %>
  <%= javascript_include_tag :all %>
  <%= csrf_meta_tag %>
</head>
<body>
    <div id="outer">
        <div class="contentwidth main">
            <%= render 'layouts/header' %>
        </div>

        <%= yield %>

</body>
</html>

它呈现的部分 (_header.html.erb) 看起来像这样:

<div class="logo">
    <h1><a href="index.html">minimal.</a></h1>
</div><!-- end logo -->

但是,输出的 HTML 的摘录错放了(错误缩进的)括号(请参阅我在下面代码中的注释):

<body>
    <div id="outer">

        <div class="contentwidth main">
                        <div class="logo"> <<<Why is this so far to the right?
    <h1><a href="index.html">minimal.</a></h1>   <<<Why is this so far to the left?
</div><!-- end logo -->

这是怎么回事?如果我在 application.html.erb 中对 _header.html.erb 部分的调用缩进了四个空格,我是否需要将部分中的代码缩进至少相同的数量才能正确嵌套?

最佳答案

呈现的部分的第一行缩进为 <%= render 'layouts/header' %>在 application.html.erb 中。但是所有其他代码行都没有进一步缩进,只是左对齐,因为它们在您的局部代码中。它也困扰着我,这也是我开始使用 haml 的部分原因。

关于html - 输出的 HTML 中的 Rails 缩进会发生什么情况?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5690803/

相关文章:

html - 使用 HTML5 输入模式匹配字符串但不匹配空格

ruby-on-rails - Rails ActionView::MissingTemplate 用于不应该存在的模板

vb.net - Visual Studio : Override "Smart" indenting only for a few specific lines

python : "Indentation Error: unindent does not match any outer indentation level"

jquery - Rails 使用 aws-sdk gem 和 heroku 上的 jQuery-File-Upload 直接进行 S3 上传

python - 复制粘贴到 Python 交互式解释器和缩进

php - BeautifulSoup 和 php/html 文件

html - 如何使用左侧的 Logo 和菜单链接以及右侧的表单控件来设置内联导航栏的样式

html - 背景图像不可用时的 Font Awesome 图标

ruby-on-rails - Belongs_to 和 where 条件