Problem with escaping HTML characters in Rails 3
-
30-10-2019 - |
Frage
I use foo
helper function in my view:
<%= foo ["hello", "stack", "overflow"] %>
When foo
is defined like this:
def foo(arr)
result = ''
arr.each do |a|
result += content_tag(:div, a)
end
result
end
The page renders:
<div>hello</div><div>stack</div><div>overflow</div>
But, if change foo
's definition to be:
def foo(arr)
content_tag(:div, arr[0]) + content_tag(:div, arr[1]) + content_tag(:div, arr[2])
end
I get the expected result:
hello
stack
overflow
How would you fix foo
's definition above to get the expected result ? (i.e. I don't want the characters to be escaped)
Keine korrekte Lösung
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow