【问题标题】:Haml to HTML/erb...can anyone see the mistake I'm makingHaml 到 HTML/erb ......谁能看到我犯的错误
【发布时间】:2012-01-03 07:44:41
【问题描述】:

我派生了一个使用 Haml 的 Rails 项目,但我还没有真正学习过。有一个在线转换器帮助我处理 HTML,但它忽略了 erb,当我测试我自己的转换时,flash 消息没有与之关联的类,所以我知道我做错了,但我可以'不明白为什么。

注意(不要担心haml中的间距。在我的代码中

原版火腿

 - if flash[:notice]
        .alert-message.warning
          %p
            = flash[:notice]
      - if flash[:error]
        .alert-message.error
          %p
            = flash[:error]

HTML 翻译错误

<% if flash[:notice] %>
    <div class="alert-message.warning">
    <p>
     <%= flash[:notice] %>
    </p>
    </div>
 <% end %>
   <% if flash[:error] %>
   <div class="alert-message.error">
   <p>
   <%= flash[:error] %>
   </p>
   </div>
   <% end %>

【问题讨论】:

    标签: html ruby-on-rails haml


    【解决方案1】:

    在第一行之后你有一个巨大的缩进。应该是2个空格。

    已编辑:如果您需要转换一小部分haml,您可以学习如何手动转换它。有一个小haml tutorial,您可以在其中学习一些基础知识。 那部分haml可以变成如下erb:

    <% if flash[:notice] %>
      <div class="alert-message warning">
       <p><%= flash[:notice] %></p>
      </div>
    <% end %>
    <% if flash[:error] %>
      <div class="alert-message error">
       <p><%= flash[:error] %></p>
      </div>
    <% end %>
    

    在哪里: -&lt;%

    =&lt;%=相同

    %p (%tag_name) -> &lt;p&gt;

    .class -> %div.class -> &lt;div class="class"

    已编辑#2: 从生成的html判断&lt;div class="alert-message.warning"&gt;应该是&lt;div class="alert-message warning"&gt;(点替换为类之间的空格)

    【讨论】:

    • 对不起,有一半的问题是看不见的。我正在将 FROM haml 翻译成 html/erb..html/erb 不起作用
    • 所以我做对了。我的和你的一样,但它在我的网站上不起作用..hmm.
    • 问题是我把“。”而不是空格。没看到那个。谢谢
    猜你喜欢
    • 2020-10-03
    • 2010-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多