/ Published in: Rails
Expand |
Embed | Plain Text
# require 'rubygems' if using this outside of Rails require 'fastercsv' def dump_csv @users = User.find(:all, :order => "lastname ASC") @outfile = "members_" + Time.now.strftime("%m-%d-%Y") + ".csv" csv_data = FasterCSV.generate do |csv| csv << [ "Last Name", "First Name", "Username", "Email", "Company", "Phone", "Fax", "Address", "City", "State", "Zip Code" ] @users.each do |user| csv << [ user.lastname, user.firstname, user.username, user.email, user.company, user.phone, user.fax, user.address + " " + user.cb_addresstwo, user.city, user.state, user.zip ] end end send_data csv_data, :type => 'text/csv; charset=iso-8859-1; header=present', :disposition => "attachment; filename=#{@outfile}" flash[:notice] = "Export complete!" end
Comments
Subscribe to comments
You need to login to post a comment.

hi,
Its nice and working perfect in my rails application. But i want to change the row colour can you help?
regards k.Balasubramaniam.
hi,
Its nice and working perfect in my rails application. But i want to change the row colour can you help?
regards k.Balasubramaniam.
This works great except for the flash[:notice] doesn't show until I reload the view. I am calling this from a link_to, is there a better way or am I missing something?
report controller def export_users #your code here end
view