How can I use strip_tags in regular Ruby code (non-rails)?

前端 未结 8 1657
广开言路
广开言路 2020-12-31 00:09

I need to turn HTML into plain text. There\'s a nice function that does that in ActionView\'s SanitizeHelper, but I have trouble understanding how I can reference it and use

8条回答
  •  北海茫月
    2020-12-31 00:18

    If you don't use it very often, then you can use:

    ActionView::Base.full_sanitizer.sanitize(your_html_string)
    

    else you can define a method in test_helper.rb file like:

    def strip_html_tags(string)
        ActionView::Base.full_sanitizer.sanitize(string)
    end
    

    And then in your test.rb file, use this like:

    strip_html_tags(your_html_string)
    

提交回复
热议问题