Refer to model field by string variable that contains the name of the field?
ruby-on-rails
Solution
If `b` is an instance variable or method of a `Color`, use the `send` method from `Object`
c = Color.all
b = 'color_name'
c[0].send(b.to_sym)
Problem
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