Skip to content

Instantly share code, notes, and snippets.

@coreymartella
Created July 31, 2012 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coreymartella/3217786 to your computer and use it in GitHub Desktop.
Save coreymartella/3217786 to your computer and use it in GitHub Desktop.
pages_controller.rb
<html>
<head>
<style type="text/css">
table {border: 0; border-collapse: collapse;}
th, td {text-align: left; padding: 2px;}
.odd {background: #eee;}
</style>
</head>
<body>
<table>
<thead>
<tr>
<% @fields.each do |field| %>
<th><%= field %></th>
<% end %>
</tr>
</thead>
<tbody>
<% @rows.each_with_index do |row,i| %>
<tr class="<%= i % 2 == 1 ? :odd : :even %>">
<% @fields.each do |field| %>
<td><%= row[field] %></td>
<% end %>
</tr>
<% end %>
</tbody>
</table>
</body>
</html>
class PagesController < ApplicationController
def index
xml = Hpricot.parse File.read("/Users/cmartella/downloads/cqs.xml")
@fields = xml.search("//columnname").map(&:inner_text)
@rows = xml.search("//record").map do |record|
record.search("/field").reduce({}) do |hash,field|
hash.merge(field['name'] => field.inner_text)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment