2

I'm trying to build a formatted html string using a rails helper method, which lives in application_helper.rb.

def comment_posted_tag(actor_id,date)
  ... irrelevant code removed
  str =  "<b>" + actor_name + "</b>" + " on " + date.strftime("%d %b %Y at %H:%M")
  return str.html_safe
end

I'm calling it like this in the view:

<%= comment_posted_tag(dialog_comment.actor_id,dialog_comment.updated_at) %>

For some reason the tags are not coming through. Ideally I'd like to attached a css class to the actor_name string. I've tried it with and without the html_safe but neither work.

1 Answer 1

3

Always use content_tag for this kind of job:

def comment_posted_tag(actor_name, date)
  content_tag(:span, :class => 'yours') do
    content_tag(:b, actor_name) + ' on ' + date.strftime("%d %b %Y at %H:%M")
  end
end
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.