Nani Nani - 1 year ago 117
Ruby Question

How to remove css attributes from Rich Text to convert ruby string?

i have blocked here from last few hours. the problem is

var rich_text = "<h1 class='some', some_other='some'>This is sentense </h1>"

i want remove css classes and other attributes from this string. suggest me a better way to do this.

output should be like this

<h1>This is sentense </h1>

i have tried with
methods. which is not use full to me. because i want to delete all attributes from rich text.
any suggestions would be great appreciated. Thank you

Answer Source

Hey you can use SanitizeHelper just pass attributes array as blank so it removes all attributes from tag

rich_text = "<h1 class='some', some_other='some'>This is sentense </h1>"

helper.sanitize(rich_text,:attributes => [])
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download