2011-03-31 132 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} 
相關問題