# Error customization problem

**URL:** <https://www.ruby-forum.com/t/error-customization-problem/196064>\
**Category:** Rails\
**Created:** [October 6, 2010, 8:56am UTC](https://www.ruby-forum.com/t/error-customization-problem/196064 "2010-10-06T08:56:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sunfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@sunfish](https://www.ruby-forum.com/u/sunfish)\
**Post date:** [October 6, 2010, 8:56am UTC](https://www.ruby-forum.com/t/error-customization-problem/196064/1 "2010-10-06T08:56:17Z")

</div>

Hi,

I have following models

class User \< ActiveRecord::Base  
has\_many :addresses, :as =\>:addressee, :dependent =\> :destroy  
accepts\_nested\_attributes\_for :addresses, :allow\_destroy =\> true  
end

class Address \< ActiveRecord::Base

belongs\_to :addressee, :polymorphic =\> true

validates\_presence\_of :address1, :maximum =\> 50,:message =\> “Address1  
cannot be blank.”  
validates\_presence\_of :city,:message =\> “City cannot be blank.”  
validates\_presence\_of :state,:message =\> “State cannot be blank.”  
validates\_presence\_of :zipcode,:message =\> “Zip Code cannot be  
blank.”  
validates\_presence\_of :country,:message =\> “Country cannot be blank.”  
end

also in my environment file(environment.rb)

#Customize errors  
config.action\_view.field\_error\_proc = Proc.new do |html\_tag, instance|  
if instance.error\_message.kind\_of?(Array)  
%{

#{html\_tag}
•#{[instance.error\_message].join(’  
•’)}}  
else  
%{
#{html\_tag}
•#{[instance.error\_message].flatten.first}}  
end  
end

when i am creating user it will give me all model validations error  
properly.  
but when i am updating user it only show user model validations. for  
addresses if any error is there or it is not showing that message inside  
my form. i am not understanding why this is happening? anybody can give  
me how can i debug this problem?  
i have used field\_error\_proc for customizing my error messages(show  
error for field level)

Please help me out what’s going wrong?
