Skip to content

Instantly share code, notes, and snippets.

@Twisol
Created October 10, 2010 22:59
Show Gist options
  • Save Twisol/619668 to your computer and use it in GitHub Desktop.
Save Twisol/619668 to your computer and use it in GitHub Desktop.
# Causes Rails to output HTML instead of XHTML.
# Example: <%= image_tag "bacon.png" %>
# Before: <img src="/images/bacon.png" />
# After: <img src="/images/bacon.png">
module ActionView::Helpers::TagHelper
# Force the 'open' argument to always be true.
old_tag = instance_method(:tag)
define_method :tag do |name, options = nil, open = true, escape = true|
old_tag.bind(self).call(name, options, true, escape)
end
end
module ActionView::Helpers::CsrfHelper
# csrf_meta_tag, unlike the other helpers, does not use 'tag' internally.
# Hence, it needs to be manually modified here.
def csrf_meta_tag
if protect_against_forgery?
csrf = tag("meta", {:name => "csrf-param", :content => "#{Rack::Utils.escape_html(request_forgery_protection_token)}"})
csrf << "\n"
csrf << tag("meta", {:name => "csrf-token", :content => "#{Rack::Utils.escape_html(form_authenticity_token)}"})
csrf.html_safe
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment