instance method
safe_join
Ruby on Rails 8.1.2
Since v3.1.12Signature
safe_join(array, sep = $,)
This method returns an HTML safe string similar to what Array#join would return. The array is flattened, and all items, including the supplied separator, are HTML escaped unless they are HTML safe, and the returned string is marked as HTML safe.
safe_join([tag.p("foo"), "<p>bar</p>"], "<br>") # => "<p>foo</p><br><p>bar</p>" safe_join([tag.p("foo"), tag.p("bar")], tag.br) # => "<p>foo</p><br><p>bar</p>"
Parameters
-
arrayreq -
sepopt = $
Source
# File actionview/lib/action_view/helpers/output_safety_helper.rb, line 33
def safe_join(array, sep = $,)
sep = ERB::Util.unwrapped_html_escape(sep)
array.flatten.map! { |i| ERB::Util.unwrapped_html_escape(i) }.join(sep).html_safe
end
Defined in actionview/lib/action_view/helpers/output_safety_helper.rb line 33
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionView::Helpers::OutputSafetyHelper