@@ -57,23 +57,29 @@ def create
5757
5858 action_auth_level :show , :student
5959 def show
60- attached_file = @attachment . attachment_file
61- unless attached_file . attached?
62- COURSE_LOGGER . log ( "No file attached to attachment '#{ @attachment . name } '" )
63-
64- flash [ :error ] = "No file attached to attachment '#{ @attachment . name } '"
65- redirect_to ( [ @course , :attachments ] ) && return
66- end
6760 if @cud . instructor? || @attachment . released?
6861 begin
69- send_data attached_file . download , filename : @attachment . filename ,
70- type : @attachment . mime_type
62+ attached_file = @attachment . attachment_file
63+ if attached_file . attached?
64+ send_data attached_file . download , filename : @attachment . filename ,
65+ type : @attachment . mime_type
66+ return
67+ end
68+
69+ old_attachment_path = Rails . root . join ( "attachments" , @attachment . filename )
70+ if File . exist? ( old_attachment_path )
71+ send_file old_attachment_path , filename : @attachment . filename , type : @attachment . mime_type
72+ else
73+ COURSE_LOGGER . log ( "No file attached to attachment '#{ @attachment . name } '" )
74+ flash [ :error ] = "No file attached to attachment '#{ @attachment . name } '"
75+ redirect_to ( [ @course , :attachments ] )
76+ end
77+ return
7178 rescue StandardError
7279 COURSE_LOGGER . log ( "Error viewing attachment '#{ @attachment . name } '" )
7380 flash [ :error ] = "Error viewing attachment '#{ @attachment . name } '"
74- redirect_to ( [ @course , @assessment ] )
81+ redirect_to ( [ @course , @assessment ] ) && return
7582 end
76- return
7783 end
7884
7985 flash [ :error ] = "You are unauthorized to view this attachment"
0 commit comments