hi all, i have a sql obj (in controller) ex: @c = C.find_by_sql("select * from a,b") and i want to print all content in this sql obj c in view . is there a better way or easy way to print all column name(scheme) in @c with a table in <th> and just to print all content in @c with a table in <tr> <td> ? my orginal way : <table> <th>a</th> <th>b</th> <th>c</th> <% # may i just print all column name in @c with just a iterator ? %> <% for c in @c %> <tr> <td>c.a</td> <td>c.b</td> <td>c.c</td> <% # may i just print all content in @c with just a iterator ? %> </tr> <%end%> </table> thanks -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
<% for column in {tablename}.content_columns %> <th><%= column.human_name %></th> <% end %> This is all. On 24 jun, 05:37, Feng <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> hi all, > > i have a sql obj > > (in controller) > ex: @c = C.find_by_sql("select * from a,b") > > and i want to print all content in this sql obj c in view . > > is there a better way or easy way to print all column name(scheme) in @c > with a table in <th> > and just to print all content in @c with a table in <tr> <td> ? > > my orginal way : > > <table> > <th>a</th> > <th>b</th> > <th>c</th> > <% # may i just print all column name in @c with just a iterator ? %> > > <% for c in @c %> > <tr> > <td>c.a</td> > <td>c.b</td> > <td>c.c</td> > > <% # may i just print all content in @c with just a iterator ? %> > </tr> > <%end%> > > </table> > > thanks > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
nicolas55ar wrote:> <% for column in {tablename}.content_columns %> > <th><%= column.human_name %></th> > <% end %> > > This is all.thanks, but it works only with "table", and i want to take with "query result", ex: @c = C.find_by_sql("select * from a,b") -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---