# Sentry and Rails validations

**URL:** <https://www.ruby-forum.com/t/sentry-and-rails-validations/123456>\
**Category:** Rails\
**Created:** [December 17, 2007, 11:15pm UTC](https://www.ruby-forum.com/t/sentry-and-rails-validations/123456 "2007-12-17T23:15:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Olly\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/eb8c5e/32.png) [@Olly\_L](https://www.ruby-forum.com/u/Olly_L)\
**Post date:** [December 17, 2007, 11:15pm UTC](https://www.ruby-forum.com/t/sentry-and-rails-validations/123456/1 "2007-12-17T23:15:27Z")

</div>

I’m looking at using Sentry ([http://sentry.rubyforge.org/](http://sentry.rubyforge.org/)) to encrypt  
a number of sensitive fields in an ActiveRecord model. I’m  
encrypting a field which is currently called account\_number. Sentry  
requires that the database field is renamed to crypted\_account\_number  
whilst a virtual field on the model called ‘account\_number’ is added,  
which returns the unencrypted fields.

So far so good.

However, I have validates\_presence\_of and validates\_format\_of helpers  
for this field (:account\_number) and the view form containing this  
field is currently using f.account\_number. Obviously I’d really like  
these helpers to just work even when using Sentry, but this (as far as  
I can see) isn’t possible. I can change the validates\_presence\_of  
helper to reference :crypted\_account\_number, but clearly this won’t  
work for the format helper. Is the best solution here to implement a  
bespoke validate method on my model which performs this validation, or  
is there a better way which I’m not seeing?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Olly\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/eb8c5e/32.png) [@Olly\_L](https://www.ruby-forum.com/u/Olly_L)\
**Post date:** [December 17, 2007, 11:58pm UTC](https://www.ruby-forum.com/t/sentry-and-rails-validations/123456/2 "2007-12-17T23:58:14Z")

</div>

On 12/17/07, Olly L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> However, I have validates\_presence\_of and validates\_format\_of helpers  
> for this field (:account\_number) and the view form containing this  
> field is currently using f.account\_number. Obviously I’d really like  
> these helpers to just work even when using Sentry, but this (as far as  
> I can see) isn’t possible. I can change the validates\_presence\_of  
> helper to reference :crypted\_account\_number, but clearly this won’t  
> work for the format helper. Is the best solution here to implement a  
> bespoke validate method on my model which performs this validation, or  
> is there a better way which I’m not seeing?

Wow, someone using sentry? First plugin I ever wrote 🙂

Um, try :allow\_nil =\> true so it only validates #account\_number if  
it’s set. I wouldn’t bother with validates\_presence\_of though.

–  
Rick O.  
[http://lighthouseapp.com](http://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)
