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
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!