# Create yor own validation helper

**URL:** <https://www.ruby-forum.com/t/create-yor-own-validation-helper/129607>\
**Category:** Rails\
**Created:** [February 20, 2008, 1:30am UTC](https://www.ruby-forum.com/t/create-yor-own-validation-helper/129607 "2008-02-20T01:30:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![maxmustermann](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ebca7d/32.png) [@maxmustermann](https://www.ruby-forum.com/u/maxmustermann)\
**Post date:** [February 20, 2008, 1:30am UTC](https://www.ruby-forum.com/t/create-yor-own-validation-helper/129607/1 "2008-02-20T01:30:37Z")

</div>

Hi there!  
Does anyone know if it’s possible to create your own  
customized validation helper?  
If yes, how do I do that?

cheers guys  
julius

---

<div class="post-metadata">

**Author:** ![maxmustermann](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ebca7d/32.png) [@maxmustermann](https://www.ruby-forum.com/u/maxmustermann)\
**Post date:** [February 20, 2008, 1:32am UTC](https://www.ruby-forum.com/t/create-yor-own-validation-helper/129607/2 "2008-02-20T01:32:54Z")

</div>

What do you want it to do?

On Feb 20, 2008 11:00 AM, Julius C.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> >

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

Feel free to add me to MSN and/or GTalk as this email.

---

<div class="post-metadata">

**Author:** ![maxmustermann](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ebca7d/32.png) [@maxmustermann](https://www.ruby-forum.com/u/maxmustermann)\
**Post date:** [February 20, 2008, 1:41am UTC](https://www.ruby-forum.com/t/create-yor-own-validation-helper/129607/3 "2008-02-20T01:41:00Z")

</div>

Well, my validation is checking some input, so tat it has only 2  
decimals.  
I use validate\_format\_of and validate\_numericality\_of. Now, what I  
wanted to do is, combine both in one customized helper  
(validate\_2\_decimals\_of for example)because I’m using those methods  
quite often.  
just to make it easy to maintain and stuff…  
Any idea?

---

<div class="post-metadata">

**Author:** ![maxmustermann](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ebca7d/32.png) [@maxmustermann](https://www.ruby-forum.com/u/maxmustermann)\
**Post date:** [February 20, 2008, 8:01pm UTC](https://www.ruby-forum.com/t/create-yor-own-validation-helper/129607/4 "2008-02-20T20:01:19Z")

</div>

You can extend the default Rails validations through Ruby’s great  
extensions capability. Just create a file (my\_validations.rb) in your  
project’s lib folder and then in environment.rb add: require  
‘my\_validations’.

module ActiveRecord  
module Validations  
module ClassMethods

```
  def validates_2_decimals_of
    # ...
  end

end

```

end  
end

Jason Arora

On Feb 19, 4:41 pm, Julius C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
