jraglin
2010-May-27 14:20 UTC
Creating a report generator within a mysql database to be read on rails.
Hello, 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? Thanks -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-May-27 22:02 UTC
Re: Creating a report generator within a mysql database to b
jraglin wrote:> Hello, > > 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? > > ThanksBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Mutesa
2010-May-28 07:56 UTC
Re: Creating a report generator within a mysql database to be read on rails.
Hi, 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 : #The action def import_csv result = YourModel.find(:all, :conditions => "your_condition") @outfile = "your_csv_report_name_" + Time.now.strftime("%m-%d-%Y") + ".csv" csv_data = FasterCSV.generate do |csv| #field names csv << ["Field_name_1"] csv << ["Field_name_2"] #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 %> Hope this helps! Regards, On May 27, 4:20 pm, jraglin <jrag...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello, > > 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? > > Thanks-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.