Rails 4 raw html_safe not working
Asked Answered
P

1

7

I am not able to escape raw html tags in the view

<% array =  @article.tags.collect { |p| (link_to p.name, '#') } %>
<%= array.join(' , ') %>

Raw and html_safe

<% array =  @article.tags.collect { |p| raw (link_to p.name, '#') } %>
<% array =  @article.tags.collect { |p| (link_to p.name, '#').html_safe } %>

Giving me this output, without escaping the html tags

<a href="#">tag1</a> , <a href="#">tag2</a> , <a href="#">tag4</a> 
Pounce answered 25/4, 2013 at 14:35 Comment(1)
also explained at: #4251784Galarza
P
9

This solved my problem

<%= raw (@article.tags.map { |p| (link_to p.name, '#') }.join(' , ')) %>
Pounce answered 25/4, 2013 at 14:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.