Below code will help to export the data in excel in Ruby on Rails
#Controller
1 2 3 4 5 6 7 | class UserController < ApplicationControllerdef exportheaders['Content-Type'] = "application/vnd.ms-excel"headers['Content-Disposition'] = 'attachment; filename="report.xls"'headers['Cache-Control'] = ''@users = User.find(:all)end |
#View
export.html.erb
1 <%=link_to "Export as Excel", export_person_url %>
_report.html.erb
12345678910 "1"> <% @users.each do |u| %> <% end %>
Name
<%= u.name %>
No comments:
Post a Comment