Ransack 搜索结果 - to_xls? [英] Ransack Search Results - to_xls?

查看:36
本文介绍了Ransack 搜索结果 - to_xls?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行良好的搜索表单,我想为用户添加一个导出,以将结果集的内容发送到 XLS 文件.

I have a ransack search form which is working wonderfully, I would like to add an export for the user to send the contents of the result set to an XLS file.

我也成功地实现了 to_xls,但是它为我提供了我正在搜索的对象的最大范围,而不是视图中显示的过滤结果.

I have implemented the to_xls sucessfully as well, however it is giving me back the fullest possible scope of the object I am searching, and not the filtered results that are shown in the view.

def index

  @search = Expense.search(params[:q])
  @expense_list = @search.result.sort_by(&:expense_date) 

    respond_to do |format|
      format.html
      format.xml { render :xml => @expense_list }
      format.xls { send_data @expense_list.to_xls, :filename => '123.xls'}
    end

end

是否与ransack使用GET方法的方式有关?任何帮助都会很棒.

Does it have something to do with how ransack uses the GET method? Any help would be great.

谢谢!

推荐答案

我知道这是一个 hack,在花了很多小时没有得到它之后,我还是使用了它.

I know this is such a hack, after spending many hours of not getting it, I used it anyway.

<a href="/expenses.xls?<%= request.fullpath.split("?")[1]  %>">make xls</a>

所以基本上它在 ? 之后使用搜索路径,然后将它添加到您的 model.xls 输出路径,然后它就可以工作了.我自己讨厌它,必须有更好的方法,但有期限.

so basically it takes the searchpath after the ?, then adds it to your model.xls output path and then it works. I hate it myself, there must be a better way, but deadlines.

这里有一个很好的链接.

这篇关于Ransack 搜索结果 - to_xls?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆