Update for the rails demo
In class Monday I demoed an updated version of the project from the previous Wednesday
updated csvdemo_controller.rb
require 'csv'
class CsvdemoController < ApplicationController
def initialize
@file = 'demoData.csv'
end
def index
@table={"headings" => ["Name", "Category", "City", "Rating"],
"body" => CSV::Reader.parse(File.open(@file))
}
end
def create
@newData = params
end
end
New index.rhtml ( views/csvdemo/index.rhtml)
<h1>Csvdemo</h1>
<% form_tag :action => "create" do %>
<table>
<tr>
<% @table["headings"].each do |heading| %>
<td>
<b><%= heading %></b>
</td>
<%end %>
</tr>
<% @table["body"].each do |row| %>
<tr>
<% row.each do |col| %>
<td>
<%= col %>
</td>
<% end %>
</tr>
<% end %>
<tr>
<td>
<%= @newData %>
</td>
</tr>
</table>
<p><%= text_field_tag :symbol %> <%= check_box_tag :checkName %></p>
<p><%= submit_tag "Do it!" %></p>
<% end %>
create.rhtml ( views/csvdemo/index.rhtml)
<h1>Csvdemo#create</h1>
<p>
you added
<%=@newData.inspect %></p>