我正在创建信息学家学院(不是公共网站)使用的内部工具。我需要以各种方式导出我的数据,我想让我的同事根据他们的需要编写导出方法。
所以我想将特定ruby文件的特定方法作为go_to()方法运行,然后返回。
该函数位于 Rails 应用程序 (app/views/export/templates/my_template/export.rb) 中,我想从我的导出控制器运行它,它在多步骤向导中获取数据。
如何从我的导出控制器“跳转”到特定方法来操作数据(作为预处理函数)?
我需要扩展我的控制器吗?
class ExportController < ApplicationController
require 'spreadsheet'
# Step 5 : Exporting
def step5
# Creating Spreadsheet variable called "book"
book = Spreadsheet::Workbook.new
sheet = book.create_worksheet
# Selecting points to export
@project = Project.find(session[:current_project_id])
@points = @project.points
# HERE : Jump to app/views/export/templates/my_template/export.rb
# WITH SOME PARAMETERS AS @points, book THAT WILL MAKE SOME EXTRA QUERIES
# THEN COME BACK TO RENDER THE EXCEL FILE WITH THE PROCESSED DATA
# Sending to browser without saving it on the server
data = StringIO.new
book.write data
send_data(data.string, {
:disposition => 'attachment',
:encoding => 'utf8',
:stream => false,
:type => 'application/excel',
:filename => 'some_filename.xls'})
#send_data data.string, :filename => "yourfile.xls", :type => "application/vnd.ms-excel", :x_sendfile=>true
# redirect_to "export#step6" # this is for now not working because of the render of the xls file
end
end