I can’t figure out how to word this for a google search – pardon. If I have a model like:
c = Color.all
I could say:
c.Color[0].color_name
So if I then have a variable that contains the name of a field in that model like:
b = 'color_name'
How could I say (“c.color_name”) like this using the string with the field name:
c[0].b
Or, I mean tell Ruby/Rails to use the contents of the vaiable as the field name:
c[0].[the string value of b]
I’ve fumbled around trying everything I can think of but the syntax for this I can’t figure out.
Thanks!
Rails 2.3.5 / Ruby 1.8.7
If
bis an instance variable or method of aColor, use thesendmethod fromObject