user1730335 user1730335 - 1 year ago 70
Ruby Question

Using helper method and Ruby enumerable to return html formatted objects

Apologies for the noob question, but I can't seem to figure out how to return formatted HTML objects using a ruby enumerable and a helper. I want to remove the brackets. Is there anyway to return formatted objects with an enumerable based on an array of objects?


module PostsHelper

def display_posts(posts)
if posts.any?
raw( {|p| raw("<div class='post_text_box'>#{p.body}</div>")})




<div id="post_feed">


Browser Output

picture of array of formatted html

Answer Source

You should join your array into whole string before passing it in your view. Try:

if posts.any? {|p| "<div class='post_text_box'>#{p.body}</div>"}.join.html_safe
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download