I am trying to get ALL the filtered results when exporting to CSV.
My to_csv
is working fine, and I suspect something to do with my controller.
Search around with kaminari, ransack, but seems like even exporting to csv is rare using ransack.
Any help is much appreciated.
controller.rb
@search = Order.includes(:user, :order_items).ransack(params[:q])
@orders = @search.result.order(created_at: :desc).page(params[:page])
respond_to do
|format|
format.html
format.csv { send_data @orders.to_csv, filename: "orders-#{DateTime.now.strftime("%d%m%Y%H%M")}.csv" }
end
view.html.haml
= link_to 'Download as CSV', a_o_path(request.params.merge(format: 'csv')), { class: 'btn btn-primary', style: 'float: right;' }