Hi, I have a list of emails in a users table in my database and my client wants me to export a list of these users to a format which they can paste into outlook so that they can bulk email them. Does anyone have any ideas on the best way to do this? preferably a download of the file will automatically commence on clicking of a button or link in one of my html pages. Cheers, Chris -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 8 Jan 2008, at 10:27, Chris Gallagher wrote:> > Hi, > > I have a list of emails in a users table in my database and my client > wants me to export a list of these users to a format which they can > paste into outlook so that they can bulk email them. > > Does anyone have any ideas on the best way to do this? preferably a > download of the file will automatically commence on clicking of a > button > or link in one of my html pages. >Well as far as the sending of the data you can use send_data, which allows you to send any data you want to the client (and you can set the options so that the browser will download it with the right file name etc... Fred --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Fred, I ended up with the following: def exportArtists users = Artist.getArtistList stream_csv do |csv| csv << ["email"] users.each do |u| csv << [u.Email] end end end private def stream_csv filename = params[:action] + ".csv" #this is required if you want this to work with IE if request.env[''HTTP_USER_AGENT''] =~ /msie/i headers[''Pragma''] = ''public'' headers["Content-type"] = "text/plain" headers[''Cache-Control''] = ''no-cache, must-revalidate, post-check=0, pre-check=0'' headers[''Content-Disposition''] = "attachment; filename=\"#{filename}\"" headers[''Expires''] = "0" else headers["Content-Type"] ||= ''text/csv'' headers["Content-Disposition"] = "attachment; filename=\"#{filename}\"" end render :text => Proc.new { |response, output| csv = FasterCSV.new(output, :row_sep => "\r\n") yield csv } end works pretty well and exports the file to .csv format :) Chris -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 8 Jan 2008, at 10:43, Chris Gallagher wrote:> > Hi Fred, > > I ended up with the following: > > def exportArtists > users = Artist.getArtistList > stream_csv do |csv| > csv << ["email"] > users.each do |u| > csv << [u.Email] > end > end > end > > private > > def stream_csv > filename = params[:action] + ".csv" > > #this is required if you want this to work with IE > if request.env[''HTTP_USER_AGENT''] =~ /msie/i > headers[''Pragma''] = ''public'' > headers["Content-type"] = "text/plain" > headers[''Cache-Control''] = ''no-cache, must-revalidate, > post-check=0, pre-check=0'' > headers[''Content-Disposition''] = "attachment; > filename=\"#{filename}\"" > headers[''Expires''] = "0" > else > headers["Content-Type"] ||= ''text/csv'' > headers["Content-Disposition"] = "attachment; > filename=\"#{filename}\"" > end > > render :text => Proc.new { |response, output| > csv = FasterCSV.new(output, :row_sep => "\r\n") > yield csv > } > end >Just so you know, send_data some_data, :type => ''text/csv'', :filename => filename Should accomplish most of what you''ve written above. Fred --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---