Forum: Ruby on Rails print "all column name and content in sql obj"

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F0f816437222a5266dd38fa9d87d9764?d=identicon&s=25 Feng (Guest)
on 2007-06-24 10:37
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
642215ab843322ba5d5a655ea2406731?d=identicon&s=25 nicolas55ar (Guest)
on 2007-06-24 12:56
(Received via mailing list)
<% for column in {tablename}.content_columns %>
    <th><%= column.human_name %></th>
  <% end %>

This is all.
F0f816437222a5266dd38fa9d87d9764?d=identicon&s=25 Feng (Guest)
on 2007-06-24 13:50
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")
This topic is locked and can not be replied to.