【问题标题】:is there a way to ask Rails helper functions not to produce XHTML but HTML?有没有办法让 Rails 辅助函数不生成 XHTML 而是生成 HTML?
【发布时间】:2010-10-28 15:57:38
【问题描述】:

我想使用 HTML 4.01 Strict,并在我的应用程序模板中使用了它的 DOCTYPE。但是看起来像样式表包含在辅助函数中时

<%= stylesheet_link_tag 'style' %>

生成的代码是 XHTML:

有没有办法让 Rails 生成 HTML 而不是 XHTML? (例如,HTML 将验证)

【问题讨论】:

    标签: html ruby-on-rails xhtml


    【解决方案1】:

    只是对上面包含的代码的快速修复,它确实有效。

    module ActionView::Helpers::TagHelper
      def tag_with_html(name, options = nil, open = true, escape = true)
        tag_without_html(name, options, true, escape)
      end
      alias_method_chain :tag, :html
    end
    

    感谢您的提示!

    【讨论】:

      【解决方案2】:

      不是真的,不。

      编辑:根据我下面的评论,这应该可行(我仍然感到不安,但我想不出任何会因此而崩溃的东西)

      module ActionView::Helpers::TagHelper
        def tag_with_html(name, options = nil, open, escape = true)
          tag_without_html(name, options, true, escape)
        end
        alias_method_chain :tag, :html
      end 
      

      【讨论】:

      • 有一个旧帖子,我后来发现:stackoverflow.com/questions/595867/… 但解决方案似乎有点 hacky...
      • 这些解决方案的问题,无论是stackoverflow 中的一个还是railsforum 中的一个,都只是为open 参数提供了一个默认值。许多 Rails 助手明确地将其设置为 false,因此默认值将无效。不过想一想,在 HTML 中从来不需要有一个自闭合标签。因此,如果您实际上只是将close 参数覆盖为始终为假,那么这些示例应该可以工作。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-28
      • 1970-01-01
      相关资源
      最近更新 更多