# Validation that works in the controller

**URL:** <https://www.ruby-forum.com/t/validation-that-works-in-the-controller/72307>\
**Category:** Rails\
**Created:** [December 19, 2005, 12:01pm UTC](https://www.ruby-forum.com/t/validation-that-works-in-the-controller/72307 "2005-12-19T12:01:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Colin\_JN\_Breame](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f05b48/32.png) [@Colin\_JN\_Breame](https://www.ruby-forum.com/u/Colin_JN_Breame)\
**Post date:** [December 19, 2005, 12:01pm UTC](https://www.ruby-forum.com/t/validation-that-works-in-the-controller/72307/1 "2005-12-19T12:01:59Z")

</div>

Hi,

Is there a way of validating input inside the controller? or an  
equivalent to  
ActiveRecord::Validations::ClassMethods.validates\_presence\_of ?

Cheers,

– Colin

---

<div class="post-metadata">

**Author:** ![Colin\_JN\_Breame](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f05b48/32.png) [@Colin\_JN\_Breame](https://www.ruby-forum.com/u/Colin_JN_Breame)\
**Post date:** [December 19, 2005, 3:53pm UTC](https://www.ruby-forum.com/t/validation-that-works-in-the-controller/72307/2 "2005-12-19T15:53:39Z")

</div>

just override the validate method

class Foo \< ActiveRecord::Base  
def validate  
errors.add(:name, “is blank”) if name.nil? or name == “”  
# other validations  
end  
end

then you can call @user.valid? at any time

[http://rails.rubyonrails.com/classes/ActiveRecord/Validations.html](http://rails.rubyonrails.com/classes/ActiveRecord/Validations.html)

---

<div class="post-metadata">

**Author:** ![Colin\_JN\_Breame](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f05b48/32.png) [@Colin\_JN\_Breame](https://www.ruby-forum.com/u/Colin_JN_Breame)\
**Post date:** [December 19, 2005, 4:41pm UTC](https://www.ruby-forum.com/t/validation-that-works-in-the-controller/72307/3 "2005-12-19T16:41:53Z")

</div>

On 12/19/05, Chris H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> [Peak Obsession](http://rails.rubyonrails.com/classes/ActiveRecord/Validations.html)
> 
> On 12/19/05, Colin JN Breame \<removed\_email\_address@domain.invalid \> wrote:
> 
> > Hi,
> > 
> > Is there a way of validating input inside the controller? or an equivalent  
> > to
> 
> ActiveRecord::Validations::ClassMethods.validates\_presence\_of

I have a Rails Weenie tip for validating non-model data. It basically  
creates a table-less model you can use for a form:

[http://rails.techno-weenie.net/tip/2005/11/19/validate\_your\_forms\_with\_a\_table\_less\_model](http://rails.techno-weenie.net/tip/2005/11/19/validate_your_forms_with_a_table_less_model)

–  
rick  
[http://techno-weenie.net](http://techno-weenie.net)
