My issue is that I am creating a database in MySQL and needing to
export the information in automatically generated reports (.csv), into
a web application written in Rails.
Does anyone have any advice or tutorial links as to how I may do this?
Or whether Rails or MySQL have a preferably freeware application that
could make it much easier?
My issue is that I am creating a database in MySQL and needing to
export the information in automatically generated reports (.csv), into
a web application written in Rails.
Well, you can generate the CSV files with MySQL's export feature and
read them with FasterCSV. But that seems silly: it would be better to
have the Rails app connect to the DB directly and get the data it needs.
Does anyone have any advice or tutorial links as to how I may do this?
Or whether Rails or MySQL have a preferably freeware application that
could make it much easier?
I don't know if i got you right, but it seems that you are trying to
import your mysql data into csv report?
Well, the easiest way to do this is using the fastercsv gem.
1. Install gem : sudo gem install fastercsv
2. Add on top of your controller : require 'fastercsv'
2. Create your action and view in your controller :
#Data
result.each do |table|
csv << [ table.field1 table.field2]
end
#Write data in csv format
send_data csv_data,
:type => 'text/csv; charset=iso-8859-1; header=present',
:disposition => "attachment; filename=#{@outfile}"
end
redirect_to :action => "your_action"
end
#The view import_csv.html.erb
<% form_tag :action => "import_csv" do %>
<%= submit_tag 'Print' %>
<% end %>