# Attr\_accessor problems

**URL:** <https://www.ruby-forum.com/t/attr-accessor-problems/145740>\
**Category:** Rails\
**Created:** [August 13, 2008, 2:45pm UTC](https://www.ruby-forum.com/t/attr-accessor-problems/145740 "2008-08-13T14:45:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jrm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3be4f8/32.png) [@jrm](https://www.ruby-forum.com/u/jrm)\
**Post date:** [August 13, 2008, 2:45pm UTC](https://www.ruby-forum.com/t/attr-accessor-problems/145740/1 "2008-08-13T14:45:58Z")

</div>

Hi,

I have a model (Person) with an attr\_accessor defined variable  
(copy\_employer\_address) which is used as a field in a form (checkbox/  
boolean).

When the form is submitted the value of the field is there in params  
but does not appear to be available to my model instance after a mass  
assignment (Person.new(params[:person] or  
@person.update\_attributes(params[:person]).

I am trying to access the variable from within another instance method  
using self.copy\_employer\_address.

I do not have attr\_accesssible on the model directly but the  
acts\_as\_ferret and acts\_as\_taggable macros are present.

Is what I am trying to do valid, i.e. should  
“attr\_accessor :variable\_name” allow “self.variable\_name” when mass  
assigning from params ?

Thanks

James

---

<div class="post-metadata">

**Author:** ![jrm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3be4f8/32.png) [@jrm](https://www.ruby-forum.com/u/jrm)\
**Post date:** [August 13, 2008, 4:14pm UTC](https://www.ruby-forum.com/t/attr-accessor-problems/145740/2 "2008-08-13T16:14:01Z")

</div>

I think I know the answer,

The method in which I am trying to access the copy\_employer\_address  
vaiable is a setter method also invoked by the same mass assignment,  
so the order in which the elements of params[:person] appear mean that  
the copy\_employer\_address variable has not been populated at the time  
I am trying to access it. I will move the logic into a before\_save  
callback.
