Using sanitize within a Rails controller
you can use this ActionController::Base.helpers
inside action method:
class SiteController < ApplicationController def index render :text => ActionController::Base.helpers.sanitize('<b>bold</b>') endend
Hope this helps
Rails 6:
To strip links (for example) from a text, just call:
...Rails::Html::LinkSanitizer.new.sanitize("links here will be stripped")...
I'm not sure what you're trying to do here but I'm almost 100% certain it doesn't belong in the controller.
If you want to sanitize an attribute before you save it to the DB, do so in the model with a before save callback.
Otherwise, sanitize in the view template or view helper.