Rails Exporting CSV ignore blanks

Viewed 524

I'm trying to create a simple CSV export in Rails. The export works fine except when deleting/archiving table items. I'm guessing this is because the export is encountering blanks.

This is working:

= link_to transactions_path(format: :csv) do

Except when there is a item missing from the transaction.

Tried this

= link_to transactions_path(format: :csv,skip_blanks: true) do

but I still get a ERR_INVALID_RESPONSE when calling the export

TransactionController:

respond_to :html, :json, :csv

def index
   @shops = current_user.shops

   respond_with(@shops) do |format|
     format.csv do
       response.headers['Content-Type']              = 'text/csv'
       response.headers['Content-Disposition']       = "attachment; filename=transactions-#{Time.now.strftime('%Y%m%d%H%M')}.csv"

       render inline: @shops.to_csv
    end
  end
end

Any suggestions?

3 Answers
Related