Skip to content

Instantly share code, notes, and snippets.

@mgk
Created October 20, 2021 13:43
Show Gist options
  • Save mgk/9f39590a9dd8d91dfbcebe48c7ca7495 to your computer and use it in GitHub Desktop.
Save mgk/9f39590a9dd8d91dfbcebe48c7ca7495 to your computer and use it in GitHub Desktop.
rails sanitizing iframe helper
module IframeHelper
def iframe(html_options={})
attributes =
html_options
.map {|name, value| value.nil? ? name : %(#{name}="#{value}")}
.join(" ")
sanitize("<iframe #{attributes}></iframe>",
tags: %w(iframe),
attributes: html_options.keys.map(&:to_s)
).html_safe
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment