weshatheleopard / rubyXL

Ruby lib for reading/writing/modifying .xlsx and .xlsm files
MIT License
1.27k stars 253 forks source link

MissingFile error during send_file in rails #445

Open paresatvik opened 12 months ago

paresatvik commented 12 months ago

I am getting this issue only on my production and not on my local, ActionController::MissingFile in Admin::BxBlockQuestionBankQuestionBanksController#download_sample_file Cannot read file /home/projetc/Downloads/proj/ubuntu/Desktop/prominlabs-225755-ruby/template-app/template-app/spec/support/excel/new_sample_file.xlsx Extracted source (around line #167):

collection_action :download_sample_file do new_file = "#{Rails.root}/spec/support/excel/new_sample_file1.xlsx" send_file(new_file, filename: 'sample_file.xlsx', type: 'application/xlsx')

end

this is the code :

    workbook = RubyXL::Parser.parse(file)
    new_workbook = workbook.clone 
    new_worksheet = new_workbook[0]
    new_worksheet.cell_at('H6').change_contents(grade.name)
    new_worksheet.cell_at('H7').change_contents(age_group.name)

    # add subject validation on clm #F

    new_worksheet.add_validation_list('F13:F1000', category_list)
    new_worksheet.add_validation_list('G13:G1000', BxBlockCategories::SubCategory.pluck(:name))
    new_worksheet.add_validation_list('S13:S1000', BxBlockQuestionBank::QuestionLevel.pluck(:name))

    new_file = "#{Rails.root}/spec/support/excel/new_sample_file.xlsx"
    new_workbook.write(new_file) 

and this is the way i am sending the file:

  new_file = "#{Rails.root}/spec/support/excel/new_sample_file1.xlsx"
  send_file(new_file, filename: 'sample_file.xlsx', type: 'application/xlsx') 

it's giving error at send_file that file not found