0

Here's what I'm trying to do. It's intended to replace plain text with a clickable link

<%= r.text.gsub!("\##{ht[:text]}", link_to("\##{ht[:text]}", "www.url.com")) %>

Where r.text is a string. But when it displays, the HTML is embedded in the text, it is not a link.

Some text <a href="www.url.com">Some other text</a>

How do I make it display the link?

2 Answers 2

2

You need to use html_safe, i.e. some_string.html_safe. Just make sure that the rest of the content is safe to display, being stripped of any other potentially malicious html. So you for your specific case, you'd do this:

<%= r.text.gsub!("\##{ht[:text]}", link_to("\##{ht[:text]}", "www.url.com")).html_safe %>
Sign up to request clarification or add additional context in comments.

Comments

0

try <%= raw(r.text.gsub!("\##{ht[:text]}", link_to("\##{ht[:text]}", "www.url.com"))) %>

1 Comment

No luck. I'm getting the same output.

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.