I have an hash of display names and their corresponding object attribute names called @columns. As I iterate through @columns, what is the syntax for accessing the attribute of the object using c? I get an error on the 4th line. <% for c in @columns["object_"+@object.categorie] do %> <tr> <td class="name"><%=c.first%></td> <td><%= @object.c.second %></td> </tr> <% end %> -- 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.
On Wed, Mar 24, 2010 at 10:31 AM, ES <emstolfo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have an hash of display names and their corresponding object > attribute names called @columns. > As I iterate through @columns, what is the syntax for accessing the > attribute of the object using c? I get an error on the 4th line.> <% for c in @columns["object_"+@object.categorie] do %> > <tr> > <td class="name"><%=c.first%></td> > <td><%= @object.c.second %></td> > </tr> > <% end %>It''s really hard for me to tell what you''re trying to do here. How about we simplify and take it from there? <% @columns.each do |key, value| %> <%= key %> = <% value %> <% end %> Now, what is "@object" and how does it relate to the contents of either ''key'' or ''value''? -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan -- 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.
Thanks for your reply! I have figured it out... it should be <td><%= @echantillon[c.second] %></td> On Mar 24, 7:47 pm, Hassan Schroeder <hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Wed, Mar 24, 2010 at 10:31 AM, ES <emsto...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I have an hash of display names and their corresponding object > > attribute names called @columns. > > As I iterate through @columns, what is the syntax for accessing the > > attribute of the object using c? I get an error on the 4th line. > > <% for c in @columns["object_"+...@object.categorie] do %> > > <tr> > > <td class="name"><%=c.first%></td> > > <td><%= @object.c.second %></td> > > </tr> > > <% end %> > > It''s really hard for me to tell what you''re trying to do here. How about > we simplify and take it from there? > > <% @columns.each do |key, value| %> > <%= key %> = <% value %> > <% end %> > > Now, what is "@object" and how does it relate to the contents of > either ''key'' or ''value''? > > -- > Hassan Schroeder ------------------------ hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > twitter: @hassan-- 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.