【发布时间】: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
我想使用 HTML 4.01 Strict,并在我的应用程序模板中使用了它的 DOCTYPE。但是看起来像样式表包含在辅助函数中时
<%= stylesheet_link_tag 'style' %>
生成的代码是 XHTML:
有没有办法让 Rails 生成 HTML 而不是 XHTML? (例如,HTML 将验证)
【问题讨论】:
标签: html ruby-on-rails xhtml
只是对上面包含的代码的快速修复,它确实有效。
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
感谢您的提示!
【讨论】:
不是真的,不。
编辑:根据我下面的评论,这应该可行(我仍然感到不安,但我想不出任何会因此而崩溃的东西)
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
【讨论】:
open 参数提供了一个默认值。许多 Rails 助手明确地将其设置为 false,因此默认值将无效。不过想一想,在 HTML 中从来不需要有一个自闭合标签。因此,如果您实际上只是将close 参数覆盖为始终为假,那么这些示例应该可以工作。