2011-03-31 129 views

回答

2
在HTML5

,它实际上是符合有无效元素上自行闭合的标记,如元,IMG,输入等

编号:http://www.whatwg.org/specs/web-apps/current-work/#start

+0

怎么样没有自行闭合的方式,但只是把它当作''?如果它是相同的那么为什么不使用简写? – 2011-03-31 21:47:00

+0

从兼容自闭和不自闭的意义上说,HTML5很时髦。这样做是为了方便从XML迁移。 – 2011-03-31 21:48:35

4

如果您愿意覆盖内置的Rails方法,则可以实现所需的结果。如果这样做,那么在升级到更新此方法逻辑的未来版本的Rails时,您会遇到轻微的风险导致出现问题。由于这两个表单都是根据HTML5规范生效的,因此进行下面的更改对于HTML5来说收效甚微。我能想到的唯一理由就是如果你对HTML代码风格完全迷恋,或者你正在使用HTML 4文档类型。 (以下csrf_meta_tag方法是从轨道/ ActionPack的3.0.7修改。)

module ActionView 
    # = Action View CSRF Helper 
    module Helpers 
    module CsrfHelper 
     # Returns a meta tag with the cross-site request forgery protection token 
     # for forms to use. Place this in your head. 
     def csrf_meta_tag 
     if protect_against_forgery? 
      %(<meta name="csrf-param" content="#{Rack::Utils.escape_html(request_forgery_protection_token)}">\n<meta name="csrf-token" content="#{Rack::Utils.escape_html(form_authenticity_token)}">).html_safe 
     end 
     end 
    end 
    end 
end 

我也覆盖了标签助手(改变开参数默认为true,而不是假的),这样的形式佣工不输出自 - 关闭标签。

module ActionView 
    module Helpers 
    module TagHelper 
     def tag(name, options = nil, open = true, escape = true) 
     "<#{name}#{tag_options(options, escape) if options}#{open ? ">" : " />"}".html_safe 
     end 
    end 
    end 
end 

FWIW,我存储扩展到现有的类,例如, lib/extensions/action_view.rb;这些扩展是由config/initializers/extensions.rb它由装:

Dir[File.join(Rails.root, 'lib', 'extensions', '*.rb')].each {|f| require f} 
相关问题