Ransack export results to CSV

北城以北 提交于 2019-11-30 14:47:19

To export only the filtered results as csv, you should make sure that the search parameters are included in the url you call to generate the csv.

Hence, if you want to export the results that you see on the html page you should call: reports_path(params.merge(format: 'csv')

Try this:

def index

  session[:q] = params[:q] if params[:q]
  @search = current_user.bookings.search(session[:q])

  @bookings = @search.result
  @search.build_condition
  respond_to do |format|
    format.html 
    format.csv { render text: Booking.to_csv(@bookings) }\
  end
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!