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.
I am trying to access those fields
What exactly are you trying to do with this?
On Fri, May 14, 2010 at 2:24 PM, Viorel [email protected] wrote:
It might be a trivial solution, but I can’t find it. I would
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
–
Joshua S. Martin
CONFIDENTIALITY NOTE: This e-mail message, including any attachment(s),
contains information that may be confidential, protected by the attorney
client or other legal privileges, and or proprietary non public
information.
If you are not an intended recipient of this message or an authorized
assistant to an intended recipient, please notify the sender by replying
to
this message and then delete it from your system. Use, dissemination,
distribution, or reproduction of this message and or any of its
attachments
(if any) by unintended recipients is not authorized and may be unlawful.
On May 14, 9:26 pm, Joshua M. [email protected] wrote:
What exactly are you trying to do with this?
I am trying to access these fields
Thank you Michel! I works!
On 14 May 2010 19:24, Viorel [email protected] wrote:
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?
puts ModelName.send(field_name)
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
On May 14, 10:10 pm, David [email protected] wrote:
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!
[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,
Marnen Laibow-Koser
http://www.marnen.org
[email protected]