I am trying to support free-form SQL in an internal website and just
take the string and pass it to
find_by_sql. It works fine. But, to show the result I am using the
attributes method of the ActiveRecord:Base class like thus:
<verbatim>
<% for task in @tasks %>
<% if (first == 1) %>
<% first = 0%>
<thead>
<tr>
<% for column in task.attributes %>
<th><%= column[0] %></th>
<% end %>
</tr>
<% end %>
<tr class="<%= cycle("even", "odd") %>">
<% for column in task.attributes %>
<td><%= column[1] %></td>
<% end %>
</tr>
<% end %>
</table>
</verbatim>
The funny thing is that the order of columns returned by the
attributes call is neither alphabetical nor the order specified by the
SELECT clause.
What I really would like to do is to display the columns in the order
of the SELECT clause. Any easy way to do this other than parse SELECT
on my own again?