from string to field name

I have something like this: for xx in '01'..'09'   field_name='field'+xx   puts ModelName.field_name end

My problem is that ModelName has no field named field_name, it have fields like field01, field02,...,field09. So, how do I transform a string in a field name?

It might be a trivial solution, but I can't find it. I would appreciate any help.

What exactly are you trying to do with this?

I am trying to access those fields

What exactly are you trying to do with this?

I am trying to access these fields

puts ModelName.send(field_name)

Thank you Michel! I works!

[Please quote when replying]

Viorel wrote:

Thank you Michel! I works!

Great. Now normalize your database schema to get rid of those repeating fields.

Best,

Or model_name.read_attribute(field_name)

However if you multiple fields like that, it sounds like you need a has_many relationship.

has_many :field_names

object.field_names.each do |field_mame|   # do something end

Or model_name.read_attribute(field_name)

However if you multiple fields like that, it sounds like you need a has_many relationship.

has_many :field_names

object.field_names.each do |field_mame| # do something end

> [Please quote when replying]

> Viorel wrote: > > Thank you Michel! I works!

> Great. Now normalize your database schema to get rid of those repeating > fields.

You are absolutely right, both of you. It is not my schema, but I hope that your answers will persuade those responsible. Than you!