only <a> tag execute from html content in rails

My problem is only execute tag from html content in rails.

I'm using raw, sanitize but all html tag executed

Example

@input = '<a href="http://www.example.com/">go</a> <b>bold</b> <i>bat</i>' <%=raw @input%> <%=sanitize @input%> there are same output: go bold bat

my propose is output: go <b>bold</b> <i>bat</i>

I implementing hash tag like facebook, but user input not safe many hash tag and many html tags

any idea? thank you

Upvotes: 1

Views: 96

Answers (3)

Marko Krstic
Marko Krstic

Reputation: 1447

@input = '<a href="http://www.example.com/">go</a>'.html_safe
@input += ' <b>bold</b> <i>bat</i>'
<%= @input %>

Upvotes: 0

user3926016
user3926016

Reputation:

I also struggled with this and the following will help:

@input = '<a href="http://www.example.com/">go</a>'
@input += '<b>bold</b> <i>bat</i>'.encode {xml: :text}

This will format the HTML special characters as raw symbols. More at the docs for String#encode.

Upvotes: 1

Surya
Surya

Reputation: 16002

You can do:

<% @input = '<a href="http://www.example.com/">go</a>'.html_safe+'<b>bold</b> <i>bat</i>' %>
<%= raw @input %>

Upvotes: 0

Related Questions