Current value of object.method in helper


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

  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
    select(object, method, selections, options, html_options)

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
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) ]

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

--Andrew Vit

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.