# Not seeing error message from validates\_format\_of

**URL:** <https://www.ruby-forum.com/t/not-seeing-error-message-from-validates-format-of/195397>\
**Category:** Rails\
**Created:** [September 22, 2010, 5:08pm UTC](https://www.ruby-forum.com/t/not-seeing-error-message-from-validates-format-of/195397 "2010-09-22T17:08:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![stillgar71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a5b964/32.png) [@stillgar71](https://www.ruby-forum.com/u/stillgar71)\
**Post date:** [September 22, 2010, 5:08pm UTC](https://www.ruby-forum.com/t/not-seeing-error-message-from-validates-format-of/195397/1 "2010-09-22T17:08:07Z")

</div>

Hi all any help at all on this is much appreciated.

Code is below:

I have a module with the standard Validate for email format and several  
validates in it. I have a form with the f.error.messages in it. I submit  
the form to the update method in the controller then reload the page  
with the data if there is an error. Validation is working, but error  
message does not display on reload of the page. Below I actually had to  
compare to the error message in the errors object and flash notice the  
error to see it on reload of the page. Can anyone tell how to get the  
error message to display without the flash notice on the update?

Module:  
validates\_format\_of :email\_add, :with =\>  
/\A([^@\s]+)@((?:[-a-z0-9]+.)+[a-z]{2,})\Z/i, :on =\> :update, :message  
=\> “Email must be in the format of removed\_email\_address@domain.invalid”

Form:  
%div

- form\_for @person, :url =\> {:action =\> “update” }, :html =\> {:id  
=\>“aform2”} do |f|  
= f.error\_messages  
%p  
= f.label “Email Address”  
%br  
= f.text\_field :email\_add

Controller:  
def update

```
# @person is loaded in before_filter
if @person.update_attributes(params[:person])
  flash[:notice] = "Successfully updated person."
  redirect_to @person
else

   if @person.errors[:email_add] == "Email must be in the format of

```

removed\_email\_address@domain.invalid"  
flash[:notice] = @person.errors[:email\_add]  
end

```
  redirect_to :action => 'edit', :id => @person

end
```
