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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 2007-10-27 15:26:12 -0700, Glenn <withhawaii-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 Vit --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 On Oct 27, 2:04 pm, Andrew Vit <and...-b/8mNwo5Adw@public.gmane.org> wrote:> On 2007-10-27 15:26:12 -0700, Glenn > <withhaw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 Vit--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---