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. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
What exactly are you trying to do with this? On Fri, May 14, 2010 at 2:24 PM, Viorel <viorelvladu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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. > > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > 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. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I am trying to access those fields On May 14, 9:26 pm, Joshua Martin <josmar52...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> What exactly are you trying to do with this? > > > > > > On Fri, May 14, 2010 at 2:24 PM, Viorel <viorelvl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > 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. > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com> > > . > > 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. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On May 14, 9:26 pm, Joshua Martin <josmar52...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> What exactly are you trying to do with this?I am trying to access these fields> > > > > > On Fri, May 14, 2010 at 2:24 PM, Viorel <viorelvl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > 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. > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com> > > . > > 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. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 14 May 2010 19:24, Viorel <viorelvladu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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) -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thank you Michel! I works! On May 14, 9:36 pm, Michael Pavling <pavl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 14 May 2010 19:24, Viorel <viorelvl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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) > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[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 marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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, 2:51 pm, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> [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-Koserhttp://www.marnen.org > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > -- > Posted viahttp://www.ruby-forum.com/. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On May 14, 10:10 pm, David <furb...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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, 2:51 pm, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > > > > > > [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!> > Best, > > -- > > Marnen Laibow-Koserhttp://www.marnen.org > > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > > -- > > Posted viahttp://www.ruby-forum.com/. > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.