Fix recruitment export: rename view to partial, initialize @module_app in Thread, use binary file mode
This commit is contained in:
parent
1df9e31a78
commit
5f925e402f
|
|
@ -123,14 +123,15 @@ class Admin::RecruitmentController < OrbitAdminController
|
||||||
if update_flag
|
if update_flag
|
||||||
Thread.new do
|
Thread.new do
|
||||||
begin
|
begin
|
||||||
|
@module_app = ModuleApp.where(:key => 'recruitment_mod').first
|
||||||
@recruitment = Recruitment.where(:category_id.ne=>nil).desc(:created_at)
|
@recruitment = Recruitment.where(:category_id.ne=>nil).desc(:created_at)
|
||||||
last_updated = Recruitment.max(:updated_at).to_i
|
last_updated = Recruitment.max(:updated_at).to_i
|
||||||
filename = "public/recruitment_export_#{last_updated}.xlsx"
|
filename = "public/recruitment_export_#{last_updated}.xlsx"
|
||||||
if File.exist?(filename)
|
if File.exist?(filename)
|
||||||
@thread.update(:status=>{:status=>'finish','finish_percent'=>100,'info'=>I18n.t('recruitment.read_from_cache')})
|
@thread.update(:status=>{:status=>'finish','finish_percent'=>100,'info'=>I18n.t('recruitment.read_from_cache')})
|
||||||
else
|
else
|
||||||
excel_contents = render_to_string( handlers: [:axlsx], formats: [:xlsx] , layout: false, template: 'admin/recruitment/export_excel.xlsx', locals: {:@recruitment=>@recruitment,:@thread=>@thread} )
|
excel_contents = render_to_string( handlers: [:axlsx], formats: [:xlsx] , partial: 'export_excel.xlsx' )
|
||||||
File.open(filename, 'w') do |f|
|
File.open(filename, 'wb') do |f|
|
||||||
f.write excel_contents
|
f.write excel_contents
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue