@ -124,10 +124,19 @@ class AttachmentsController < ApplicationController
end
respond_to do | format |
if @project . nil?
format . html { redirect_to_referer_or forum_memo_path ( @attachment . container . forum , @attachment . container ) }
# modify by nwb
if @attachment . container_type == 'Course'
if @course . nil?
format . html { redirect_to_referer_or forum_memo_path ( @attachment . container . forum , @attachment . container ) }
else
format . html { redirect_to_referer_or course_path ( @course ) }
end
else
format . html { redirect_to_referer_or project_path ( @project ) }
if @project . nil?
format . html { redirect_to_referer_or forum_memo_path ( @attachment . container . forum , @attachment . container ) }
else
format . html { redirect_to_referer_or project_path ( @project ) }
end
end
format . js
@ -190,9 +199,14 @@ private
def find_project
@attachment = Attachment . find ( params [ :id ] )
# Show 404 if the filename in the url is wrong
# modify by nwb
raise ActiveRecord :: RecordNotFound if params [ :filename ] && params [ :filename ] != @attachment . filename
unless @attachment . container_type == 'Bid' || @attachment . container_type == 'HomeworkAttach' || @attachment . container_type == 'Memo' || @attachment . container_type == 'Softapplication'
@project = @attachment . project
if @attachment . container_type == 'Course'
@course = @attachment . course
else
unless @attachment . container_type == 'Bid' || @attachment . container_type == 'HomeworkAttach' || @attachment . container_type == 'Memo' || @attachment . container_type == 'Softapplication'
@project = @attachment . project
end
end
rescue ActiveRecord :: RecordNotFound
render_404