Not seeing error message from validates_format_of

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 [email protected]

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

    = hidden_field_tag ‘commit’

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

[email protected]"
flash[:notice] = @person.errors[:email_add]
end

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

end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs