ruby - Rails 5: Exporting Ransack result set with axlsx -


i'm trying generate excel file using axlsx gem based on ransack gem result set.

controller:

@q = candy.ransack(params[:q]) @candies = @q.result.all 

when call @candies parameters "chocolate" in view using ransack gem, 30 or results out of 600. filtered!

but when download @candies using axlsx using:

//index.xlsx.axlsx      require 'axlsx'     xlsx_package = axlsx::package.new      workbook = xlsx_package.workbook      workbook.add_worksheet(name: "candies") |sheet|     sheet.add_row ["id", "name", "type", "date"]          @candies.each |candy|              sheet.add_row [candy.id, candy.name, candy.type, candy.date]         end     end 

it generates file 600 records!

this question similar ransack search results - to_xls? i've encountered same problem using axlsx gem instead of to_xls gem!

your search result should without "all"

@q = candy.ransack(params[:q]) @candies = @q.result put "total record = ", @candies.count 

i add trace method, can trace result, can check result rails server console / development log file


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -