【问题标题】:HAML in Rails 3 produces only doctype htmlRails 3 中的 HAML 仅生成 doctype html
【发布时间】:2011-06-15 11:32:03
【问题描述】:

我遇到了一个问题:

如果使用这样的东西:

!!! XML
!!!
%html
  %head
    %title Myspace
  %body
    %h1 I am the international space station
    %p Sign my guestbook

我只得到这个作为来源:

<!DOCTYPE html>
<html>
  <head>
    <title>Myspace</title>
  </head>
  <body>

    <h1>I am the international space station</h1>
    <p>Sign my guestbook</p>
  </body>
</html>

【问题讨论】:

    标签: html ruby-on-rails ruby xhtml haml


    【解决方案1】:

    根据HAML documentation,除了使用 HTML5 的 Rails 3 之外,XHTML 是默认的 DOCTYPE。您可以将:format 选项设置为覆盖。

    config/environment.rb:

    Haml::Template.options[:format] = :xhtml
    

    【讨论】:

      【解决方案2】:

      对我来说,把它放在environment.rb 是行不通的。

      我在config/initializers/haml.rb 中设置了一个初始化器并将其放入...

      Haml::Template.options[:format] = :xhtml
      

      添加后一定要重启服务器。

      然后在我的页面中...

      !!! XML
      !!!
      

      这会产生...

      <?xml version='1.0' encoding='utf-8' ?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-03-10
        • 2023-03-08
        • 2011-02-13
        • 2011-06-01
        • 1970-01-01
        • 2011-04-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多