Sanitize html with :before_save depending on logged in user

I woud like to sanitize attributes (with 'sanitize" gem) but unless the
model is being saved by admin. (Suppose this model doesn’t have any
relationship with user model)

In model.rb:

:before_save set_html_plain

def set_html_plain
self.body = Sanitize.clean(self.body)
end

Two questions:

  1. How can I check here if saving process has been initialized by
    specified, logged in user (admin)?

  2. What is the best way to abstract these operations to use them easily
    on multiple models?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs