Export to Excel
Controller
View (link to export)
View (Export)
Partial
class PersonController < ApplicationController def export headers['Content-Type'] = "application/vnd.ms-excel" headers['Content-Disposition'] = 'attachment; filename="report.xls"' headers['Cache-Control'] = '' @person = People.find(:all) end end
View (link to export)
<%= link_to "Export as Excel", export_person_url %>
View (Export)
#Render partial so your Layout wont be sent to the spreadsheet <%= render :partial => 'report' %>
Partial
<table border="1"> <tr> <th>Name</th> </tr> <% @person.each do |p| %> <tr> <td><%= p.name %></td> <% end %> </tr> </table>