Excel export in ruby ​​on rails

I want to export an Info page to Excel, who can tell me how I can do this? thank!

+3
source share
1 answer

Something like this might help:

http://blog.dhavalparikh.co.in/2009/04/export-to-excel-in-ruby-on-rails/

controller

class UserController < ApplicationController
  def export
    headers['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

<%= link_to "Export as Excel", export_person_url %>

_report.html.erb

<table border="1">
  <tr>
    <th>Name</th>
  </tr>
  <% @users.each do |u| %>
  <tr>
   <td><%= u.name %></td>
  <% end %>
 </tr>
</table>
+9
source

Source: https://habr.com/ru/post/1743275/


All Articles