# Validation with attribute\_accessor

**URL:** <https://www.ruby-forum.com/t/validation-with-attribute-accessor/168743>\
**Category:** Rails\
**Created:** [May 25, 2009, 11:26am UTC](https://www.ruby-forum.com/t/validation-with-attribute-accessor/168743 "2009-05-25T11:26:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [May 25, 2009, 11:26am UTC](https://www.ruby-forum.com/t/validation-with-attribute-accessor/168743/1 "2009-05-25T11:26:43Z")

</div>

hi  
I want to get country code for phone numbers in my form.  
I dont have database field for country\_code .  
So i created like below

attr\_accessor :phone , :country\_code

I have given for validation like below

validates\_presence\_of :country\_code,  
:message =\> ‘\*The country code is required.’

but it doesnot show the above validation message …  
what i should do…  
pls help me.  
Thanks

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [May 25, 2009, 12:21pm UTC](https://www.ruby-forum.com/t/validation-with-attribute-accessor/168743/2 "2009-05-25T12:21:04Z")

</div>

There’s no reason it should do that that I can think of. Which version  
of Rails are you using?

Perhaps you’re running in production mode and you forgot to reset your  
webserver after you’ve changed your model?

* * *

Blog: [http://random8.zenunit.com/](http://random8.zenunit.com/)  
Twitter: [http://twitter.com/random8r](http://twitter.com/random8r)  
Learn: [http://sensei.zenunit.com/](http://sensei.zenunit.com/)  
Latest: How to use Unix basics at [http://sensei.zenunit.com/](http://sensei.zenunit.com/)
