controller:
def export
@games = @@data
book = Spreadsheet::Workbook.new
sheet1 = book.create_worksheet name: '场次'
sheet1.row(0).concat %w(序号 主题 日期 时间)
row_num = 1
@games.each do |game|
sheet1.row(row_num).concat [row_num,
Theme.find(game.theme_id).name,
game.created_at.getlocal.to_s(:month_and_year),
game.created_at.getlocal.to_s(:time)]
row_num += 1
end
xls_report = StringIO.new
book.write xls_report
send_data(xls_report.string,
filename: 'your_excel_file_name.xls',
type: 'application/vnd.ms-excel',
disposition: 'inline')
redirect_to (request.env['HTTP_REFERER'])
end
view:
<%= link_to '导出', "/export", class: "btn btn-info btn-lg glyphicon glyphicon-export", "aria-hidden": "true",
data: { confirm: '确定导出吗?' }%>
我的页面里有一个导出按钮,指向 export 控制器。 但是我想重新回到刚才的页面而不是
/export
这要如何操作呢