# Sanitize html with :before\_save depending on logged in user

**URL:** <https://www.ruby-forum.com/t/sanitize-html-with-before-save-depending-on-logged-in-user/177774>\
**Category:** Rails\
**Created:** [October 23, 2009, 3:24pm UTC](https://www.ruby-forum.com/t/sanitize-html-with-before-save-depending-on-logged-in-user/177774 "2009-10-23T15:24:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![emmek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/a698b9/32.png) [@emmek](https://www.ruby-forum.com/u/emmek)\
**Post date:** [October 23, 2009, 3:24pm UTC](https://www.ruby-forum.com/t/sanitize-html-with-before-save-depending-on-logged-in-user/177774/1 "2009-10-23T15:24:09Z")

</div>

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?
