# Current value of object.method in helper

**URL:** <https://www.ruby-forum.com/t/current-value-of-object-method-in-helper/118510>\
**Category:** Rails\
**Created:** [October 28, 2007, 12:27am UTC](https://www.ruby-forum.com/t/current-value-of-object-method-in-helper/118510 "2007-10-28T00:27:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![glenn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@glenn](https://www.ruby-forum.com/u/glenn)\
**Post date:** [October 28, 2007, 12:27am UTC](https://www.ruby-forum.com/t/current-value-of-object-method-in-helper/118510/1 "2007-10-28T00:27:16Z")

</div>

Hi,

I am currently working to generate selection from my validation table  
where code and description pairs are stored. This works fine except  
when the current value is not exist in validation table. There are  
some old data which contains values that are no longer used and not in  
my validation table. I do not want to add old values in my validation  
table; however, I would like to display these when user open a form.

In order to accomplish this requirement, I need to dynamically add a  
current value of the record to selections in view helper like  
following.

def validation\_select(object, method, options = {}, html\_options =  
{})  
selections = Validation.find(:all).map {|v| [v.description,  
v.code] }  
selections.push [object[method], object[method]] #This does not  
work!  
select(object, method, selections, options, html\_options)  
end

Names of object and method are passed in. How do I get current value  
of object? object[method] does not work because it is just a string  
not a real object.

Say if have a model called Person which has a field called  
“ethnicity”.  
There is an instance @person, and I will call  
validation\_select(‘person’, ‘ethnicity) in my view’.  
Is there any way, I can get the current value of @person.ethnicity in  
view helper?

Thanks

Glenn

---

<div class="post-metadata">

**Author:** ![glenn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@glenn](https://www.ruby-forum.com/u/glenn)\
**Post date:** [October 28, 2007, 2:05am UTC](https://www.ruby-forum.com/t/current-value-of-object-method-in-helper/118510/2 "2007-10-28T02:05:26Z")

</div>

On 2007-10-27 15:26:12 -0700, Glenn  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) said:

> Say if have a model called Person which has a field called  
> “ethnicity”.  
> There is an instance @person, and I will call  
> validation\_select(‘person’, ‘ethnicity) in my view’.  
> Is there any way, I can get the current value of @person.ethnicity in  
> view helper?

def validation\_select(object, method, … )  
model = object.classify.constantize  
new\_option = [method, model.send(method)]  
end

I think this is what you’re looking for if I understand your Q?

–Andrew V.

---

<div class="post-metadata">

**Author:** ![glenn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@glenn](https://www.ruby-forum.com/u/glenn)\
**Post date:** [October 30, 2007, 5:22pm UTC](https://www.ruby-forum.com/t/current-value-of-object-method-in-helper/118510/3 "2007-10-30T17:22:44Z")

</div>

Hi Andrew,

Thanks you so much for your help!  
It seems “constantize” is the one I need to look into.  
I love Ruby’s strong reflection features.

Glen
