如何配置Ruby on Rails的输出标准的HTML代码,而不是使用XHTML佣工(形式,的javascript和CSS等)时?配置的Rails输出HTML输出,而不是XHTML
我不希望有斜线结尾:
<input name="email" type="text" />
如何配置Ruby on Rails的输出标准的HTML代码,而不是使用XHTML佣工(形式,的javascript和CSS等)时?配置的Rails输出HTML输出,而不是XHTML
我不希望有斜线结尾:
<input name="email" type="text" />
见http://railsforum.com/viewtopic.php?id=21941
- MarkusQ
这个答案包含在由MarkusQ提供的链接,但我想我可以把它拼出来。
您必须修改比呈现所有标签的代码,你可以做到这一点,包括下面的代码到类似的lib/dont_use_xhtml.rb
module ActionView::Helpers::TagHelper
alias :tag_without_backslash :tag
def tag(name, options = nil, open = true, escape = true)
tag_without_backslash(name, options, open, escape)
end
end
的解决方案不使用Rails的最新版本工作。有些助手会将open方法的参数'open'重写为'false'。在Rails的2.3.5我
以下工作:
module ActionView::Helpers::TagHelper
def tag_with_html_patch(name, options = nil, open = true, escape = true)
tag_without_html_patch(name, options, true, escape)
end
alias_method_chain :tag, :html_patch
end
它放入一个初始化。
钢轨2.3
:
安装宝石haml
然后添加以下初始化config/initializers/force_html4.rb
:
Haml::Template::options[:format] = :html4
module StandardistaHelper
def tag(name, options = nil, open = false, escape = true)
"<#{name}#{tag_options(options, escape) if options}>"
end
end
ActionView::Base.send :include, StandardistaHelper
ActionView::Helpers::InstanceTag.class_eval do
def tag_without_error_wrapping(name, options = nil, open = false, escape = true)
"<#{name}#{tag_options(options, escape) if options}>"
end
end