# Is there a 'right' way to do \_tag field validation?

**URL:** <https://www.ruby-forum.com/t/is-there-a-right-way-to-do-tag-field-validation/53995>\
**Category:** Rails\
**Created:** [February 19, 2006, 7:39pm UTC](https://www.ruby-forum.com/t/is-there-a-right-way-to-do-tag-field-validation/53995 "2006-02-19T19:39:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Boyce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/57b2e6/32.png) [@Chris\_Boyce](https://www.ruby-forum.com/u/Chris_Boyce)\
**Post date:** [February 19, 2006, 7:39pm UTC](https://www.ruby-forum.com/t/is-there-a-right-way-to-do-tag-field-validation/53995/1 "2006-02-19T19:39:45Z")

</div>

I’m reading the Ruby on Rails book by the pragmatic programmers, and it  
has  
a brief section on using the \_tag input fields (text\_field\_tag, etc) to  
collect form data for fields that don’t represent fields in a model.  
They  
do validation manually in the controller, which seems really clunky. Is  
there any way to normalize the form validation between model input  
fields  
and non-model fields? It seems like a waste to have  
validate\_presense\_of()  
and then write a whole nother set of validation functions to validate  
the  
tag fields.

For example, say I have a log in page that just has two input fields,  
neither of which correspond to an actual table or row because I call  
some  
other method to verify the login and password. Is there anyway that I  
can  
use all of the existing validation functionality to validate the form,  
or is  
the only way to manually check the validation in the controller? (and  
subsquently, check for any error message in the view and display it)

It would be nice if there were a way to add validation rules to specific  
elements without having to check each field in the controller.

I am very new to Ruby and Rails, so I may very well be missing something  
obvious. I’ve asked in #rubyonrails and googled some though, without  
finding  
a very satisfactory explanation, so I’m hoping someone here may be able  
to  
help me. Thanks,  
-Chris

---

<div class="post-metadata">

**Author:** ![Chris\_Boyce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/57b2e6/32.png) [@Chris\_Boyce](https://www.ruby-forum.com/u/Chris_Boyce)\
**Post date:** [February 19, 2006, 11:27pm UTC](https://www.ruby-forum.com/t/is-there-a-right-way-to-do-tag-field-validation/53995/2 "2006-02-19T23:27:06Z")

</div>

Chris Boyce wrote:

> neither of which correspond to an actual table or row because I call some  
> other method to verify the login and password. Is there anyway that I can  
> use all of the existing validation functionality to validate the form, or is  
> the only way to manually check the validation in the controller? (and  
> subsquently, check for any error message in the view and display it)

Validation in the model and view should work just fine for non-DB  
attributes  
in AR-decscended models defined as either attr\_accessors or by custom  
methods,  
and there are several solutions on the Web for fully non-DB-backed  
models.

Post an example of what is not working.

–  
We develop, watch us RoR, in numbers too big to ignore.

---

<div class="post-metadata">

**Author:** ![Chris\_Boyce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/57b2e6/32.png) [@Chris\_Boyce](https://www.ruby-forum.com/u/Chris_Boyce)\
**Post date:** [February 20, 2006, 12:54am UTC](https://www.ruby-forum.com/t/is-there-a-right-way-to-do-tag-field-validation/53995/3 "2006-02-20T00:54:51Z")

</div>

At this point, there isn’t anything ‘not’ working, I’m just trying to  
figure  
out how to do it. What would the model look like if I just wanted to  
validate the presence of a username and password field?

---

<div class="post-metadata">

**Author:** ![Chris\_Boyce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/57b2e6/32.png) [@Chris\_Boyce](https://www.ruby-forum.com/u/Chris_Boyce)\
**Post date:** [February 20, 2006, 12:27pm UTC](https://www.ruby-forum.com/t/is-there-a-right-way-to-do-tag-field-validation/53995/4 "2006-02-20T12:27:44Z")

</div>

Chris Boyce wrote:

> At this point, there isn’t anything ‘not’ working, I’m just trying to figure  
> out how to do it. What would the model look like if I just wanted to  
> validate the presence of a username and password field?

Use the usual validation helpers in the model, and active record  
form helpers in the view (rather than the \_tag variants).

–  
We develop, watch us RoR, in numbers too big to ignore.
