I have been trying to render one of my partials in a helper function located within my controller.
The first issue I encountered was that the helper was returning the e
Actually, html_safe should be used like this:-
<%= display_replies(reply).html_safe %>
To fix \n
and ["
, we need to have .join
after the loop. Like so:
Helper:
def display_replies(comment)
if comment.replies.count > 0
raw(
comment.replies.map do |reply, index|
render 'comment', index: index
end.join
)
end
end
View:
<%= display_replies(reply) %>
Note that I removed all html_safe
and replaced with raw
. And instead of each
loop, I used map
, so we don't have to create variable string
and return it after the loop.
Hope this helps!
You can use the html_safe method like this
<%= html_safe display_replies(reply) %>