# HELP attr\_accessor

**URL:** <https://www.ruby-forum.com/t/help-attr-accessor/169493>\
**Category:** Rails\
**Created:** [June 4, 2009, 1:21pm UTC](https://www.ruby-forum.com/t/help-attr-accessor/169493 "2009-06-04T13:21:21Z")\
**Posts on this page:** 9\
**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:** [June 4, 2009, 1:21pm UTC](https://www.ruby-forum.com/t/help-attr-accessor/169493/1 "2009-06-04T13:21:21Z")

</div>

Hi…  
I use non modal attribute for companyinfo modal…  
For that i have created like below

attr\_accessor :std\_code

To validate that field i included the below code in to my companyinfo  
modal.

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

it validates when i leave that field empty and shows the validation  
error.  
but even after filling the field it shows me error…  
what would be the problem…  
pls help

---

<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:** [June 4, 2009, 2:28pm UTC](https://www.ruby-forum.com/t/help-attr-accessor/169493/2 "2009-06-04T14:28:05Z")

</div>

pls help me

---

<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:** [June 4, 2009, 2:37pm UTC](https://www.ruby-forum.com/t/help-attr-accessor/169493/3 "2009-06-04T14:37:33Z")

</div>

2009/6/4 Newb N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Hi…  
> I use non modal attribute for companyinfo modal…  
> For that i have created like below
> 
> Â attr\_accessor :std\_code

I am not sure what you mean by a non modal attribute.

> pls help  
> Have you checked in the rails log that std\_code is being passed in  
> with the params?

Colin

---

<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:** [June 4, 2009, 2:43pm UTC](https://www.ruby-forum.com/t/help-attr-accessor/169493/4 "2009-06-04T14:43:44Z")

</div>

Colin L. wrote:

> 2009/6/4 Newb N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > Hi…  
> > I use non modal attribute for companyinfo modal…  
> > For that i have created like below
> > 
> > Â attr\_accessor :std\_code
> 
> I am not sure what you mean by a non modal attribute.
> 
> > pls help  
> > Have you checked in the rails log that std\_code is being passed in  
> > with the params?
> 
> Colin

yes it has been passed with params

actually i dont have any field like std\_code into my table.  
so i mentioned as non modal attribute  
i use like below in my form.  
\<%= error\_message\_on( @company, :std\_code) -%\>  
\<%= f.text\_field :std\_code, { :class =\> “txtbox”,:size =\> “2” } %\>  
pls guide me

---

<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:** [June 4, 2009, 2:54pm UTC](https://www.ruby-forum.com/t/help-attr-accessor/169493/5 "2009-06-04T14:54:05Z")

</div>

2009/6/4 Newb N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > 
> 
> ## actually i dont have any field like std\_code into my table. so i mentioned as non modal attribute i use like below in my form. \<%= error\_message\_on( @company, :std\_code) -%\> \<%= f.text\_field :std\_code, { :class =\> “txtbox”,:size =\> “2” } %\> pls guide me

I have not tried to validate an attribute that is not in the table.  
If it is not saving it what is the point of the validation?  
I would suggest using ruby-debug to break into the controller just  
before the validation and check the value of std\_code.

Colin

---

<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:** [June 4, 2009, 3:10pm UTC](https://www.ruby-forum.com/t/help-attr-accessor/169493/6 "2009-06-04T15:10:30Z")

</div>

Thank you for taking time to reply…

That is i have phone field into my table.  
I get country code and std code and phone code from the form  
after getting i append like below

1-011-5558

then i save into my phone field.

so i in my modal i have like below

attr\_accessor :country\_code,:std\_code,phone\_code

for this purpose i have to validate those three atrr\_accessor fields…

i mean is phone = country\_code+"-"+std\_code+"-"+phone\_code  
Any Helps

---

<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:** [June 4, 2009, 3:40pm UTC](https://www.ruby-forum.com/t/help-attr-accessor/169493/7 "2009-06-04T15:40:41Z")

</div>

any helps or suggestions pls…

---

<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:** [June 4, 2009, 5:17pm UTC](https://www.ruby-forum.com/t/help-attr-accessor/169493/8 "2009-06-04T17:17:34Z")

</div>

2009/6/4 Newb N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> so i in my modal i have like below
> 
> attr\_accessor :country\_code,:std\_code,phone\_code
> 
> for this purpose i have to validate those three atrr\_accessor fields…
> 
> ## i mean is phone = country\_code+“-”+std\_code+“-”+phone\_code Any Helps

Have you tried my suggestion to use ruby-debug to break into the  
controller just  
before the validation and check the value of std\_code?

Colin

---

<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:** [June 5, 2009, 10:45am UTC](https://www.ruby-forum.com/t/help-attr-accessor/169493/9 "2009-06-05T10:45:10Z")

</div>

ok…in this case you can do validation in this way…

validate :std\_code

def std\_code  
errors.add( :std\_code ) if self.std\_code and self.std\_code.blank?  
end

-Sandip R~

On Thu, Jun 4, 2009 at 8:46 PM, Colin L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > ## Any Helps
> 
> Have you tried my suggestion to use ruby-debug to break into the controller  
> just  
> before the validation and check the value of std\_code?
> 
> Colin
> 
> >

–  
Ruby on Rails Developer

> **[Blogs - Neuigkeiten - Artikel - Webseiten - Medien](https://www.sosblog.com/)**
>
> Auf SOSblog geht es um aktuelle Blogs, Neuigkeiten, Artikel, Webseiten und Medien. Wir bringen interessante neue Webseiten aus den Tiefen des Webs.

> **[Judul Situs](https://funonrails.wordpress.com/)**
>
> “Cinta tidak mengenal batas. Cinta mampu melewati rintangan, melompati pagar, menembus dinding untuk mencapai tujuannya dengan penuh harapan.” — Maya Angelou

> **[Josh Software | Custom Software Development Services & Solutions](https://joshsoftware.com/)**
>
> JoshSoftware offers custom software development Services & Solution that provides enterprise, software development services for web & mobile.
