From 33272f9193b38803934647b8486a34fea204729a Mon Sep 17 00:00:00 2001 From: Bohung Date: Wed, 21 Apr 2021 13:02:15 +0800 Subject: [PATCH] Fix bug. --- .../admin/olympiamanagements_controller.rb | 6 +++++- .../olympiamanagements/_image_form.html.erb | 16 +++++++++++++++- .../sign_up_student_data_list.html.erb | 6 +++++- .../olympiamanagements/_image_form.html.erb | 16 +++++++++++++++- 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/olympiamanagements_controller.rb b/app/controllers/admin/olympiamanagements_controller.rb index 5e21d18..a60293b 100644 --- a/app/controllers/admin/olympiamanagements_controller.rb +++ b/app/controllers/admin/olympiamanagements_controller.rb @@ -393,7 +393,11 @@ class Admin::OlympiamanagementsController < OrbitAdminController redirect_to :back else tmp_filename_data = @student.olympia_student_images.last.student_file.file.read - send_data(tmp_filename_data, type: 'image/jpg', disposition: 'attachment', filename: "#{@student.StudentName}.jpg") + file = @student.olympia_student_images.last.student_file.file.file.to_s + extname = File.extname(file) rescue ".jpg" + extname = ".jpg" if extname.blank? + mime_type = MIME::Types.type_for(file).first.content_type rescue "image/jpg" + send_data(tmp_filename_data, type: mime_type, disposition: 'attachment', filename: "#{@student.StudentName}#{extname}") end else @student_data_list = OlympiaStudentDataField.where(:sign_up_setting_id=>@sign_up_setting_id) diff --git a/app/views/admin/olympiamanagements/_image_form.html.erb b/app/views/admin/olympiamanagements/_image_form.html.erb index 5ec1217..fa9b1ff 100644 --- a/app/views/admin/olympiamanagements/_image_form.html.erb +++ b/app/views/admin/olympiamanagements/_image_form.html.erb @@ -4,7 +4,21 @@
<% if(image_form.send(image_field_name).last.send(field_name).file.present? rescue false) %>
- <%= image_tag( image_form.send(image_field_name).last.send(field_name), :size=>"120x120") %> + <% file = image_form.send(image_field_name).last.send(field_name).to_s + extname = File.extname(file) rescue ".jpg" + extname = ".jpg" if extname.blank? + file_name = URI.decode(File.basename(file)) rescue File.basename(file) + %> + <% if extname.match(/(jpg|png|gif|bmp)/i) %> + <%= image_tag( image_form.send(image_field_name).last.send(field_name), :size=>"120x120") %> + <% elsif extname.match(/pdf/i) %> + + <%=file_name%> + + + <% else %> + <%=file_name%> + <% end %>
<% end %>
diff --git a/app/views/admin/olympiamanagements/sign_up_student_data_list.html.erb b/app/views/admin/olympiamanagements/sign_up_student_data_list.html.erb index a5699b8..8c1c4b5 100644 --- a/app/views/admin/olympiamanagements/sign_up_student_data_list.html.erb +++ b/app/views/admin/olympiamanagements/sign_up_student_data_list.html.erb @@ -22,7 +22,11 @@ <%= "#{field.StudentBirthYear}-#{field.StudentBirthMonth}-#{field.StudentBirthDay}" %> <% elsif th_name == 'scan_file_of_certificate'%> <% if !field.olympia_student_images.map{|image| image.student_file.file}.select { |file| file.present?}.empty? %> - <%= "#{field.StudentName}.jpg" %><%= "> + <% file = field.olympia_student_images.map{|image| image.student_file.file}.select { |file| file.present?}.last.file.to_s + extname = File.extname(file) rescue ".jpg" + extname = ".jpg" if extname.blank? + %> + <%= "#{field.StudentName}#{extname}" %><%= "> <% else %>   <% end %> diff --git a/app/views/olympiamanagements/_image_form.html.erb b/app/views/olympiamanagements/_image_form.html.erb index f0ea441..fff642b 100644 --- a/app/views/olympiamanagements/_image_form.html.erb +++ b/app/views/olympiamanagements/_image_form.html.erb @@ -4,7 +4,21 @@
<% if(image_form.send(image_field_name).last.send(field_name).file.present? rescue false) %>
- <%= image_tag( image_form.send(image_field_name).last.send(field_name), :size=>"120x120") %> + <% file = image_form.send(image_field_name).last.send(field_name).to_s + extname = File.extname(file) rescue ".jpg" + extname = ".jpg" if extname.blank? + file_name = URI.decode(File.basename(file)) rescue File.basename(file) + %> + <% if extname.match(/(jpg|png|gif|bmp)/i) %> + <%= image_tag( image_form.send(image_field_name).last.send(field_name), :size=>"120x120") %> + <% elsif extname.match(/pdf/i) %> + + <%=file_name%> + + + <% else %> + <%=file_name%> + <% end %>
<% end %>