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