Nani Nani - 5 months ago 18
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
strip_tags
sanitize
sanitize_css
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

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 => [])