Created
July 31, 2012 15:23
-
-
Save coreymartella/3217786 to your computer and use it in GitHub Desktop.
pages_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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