# ActiveRecord Validation not working

**URL:** <https://www.ruby-forum.com/t/activerecord-validation-not-working/110787>\
**Category:** Rails\
**Created:** [July 30, 2007, 10:52pm UTC](https://www.ruby-forum.com/t/activerecord-validation-not-working/110787 "2007-07-30T22:52:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ronb722](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@ronb722](https://www.ruby-forum.com/u/ronb722)\
**Post date:** [July 30, 2007, 10:52pm UTC](https://www.ruby-forum.com/t/activerecord-validation-not-working/110787/1 "2007-07-30T22:52:30Z")

</div>

I am have trouble trying to figure out how validation is suppose to  
work. here is what I have:

validates\_length\_of :emailOptionTwo, :within =\> 1…11

When I submit my form with a value the is outside the with, I do not get  
an error. The render action int the control is being executed.

---

<div class="post-metadata">

**Author:** ![ronb722](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@ronb722](https://www.ruby-forum.com/u/ronb722)\
**Post date:** [July 31, 2007, 12:09am UTC](https://www.ruby-forum.com/t/activerecord-validation-not-working/110787/2 "2007-07-31T00:09:06Z")

</div>

you should get the error when you try to save, something like so:

def create  
@model = MyModel.new(params[:my\_model])  
if @model.save  
flash[:notice] = ‘Success’  
redirect\_to :some\_action  
else  
flash[:error] = ‘Error’  
render :action =\> :new  
end  
end

then typically in your view you’d show the errors:  
\<%= error\_messages\_for :my\_model %\>

On Jul 30, 4:52 pm, Ron B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
