Add tests, fix error handling

This commit is contained in:
Alex Sherman 2020-06-01 15:11:47 +05:00
parent e15b1283e5
commit e92afb59c1
2 changed files with 26 additions and 8 deletions

View file

@ -5,14 +5,11 @@ module Admin
def show
@ld = LegalDocument.find(params[:id])
filename = @ld.path.split('/').last
file = File.open(@ld.path).read
if file
send_data file, filename: filename
else
flash[:notice] = I18n.t('legal_doc_not_found')
redirect_to [:admin, @ld.documentable]
end
file = File.open(@ld.path)&.read
send_data file, filename: filename
rescue Errno::ENOENT
flash[:notice] = I18n.t('legal_doc_not_found')
redirect_to [:admin, @ld.documentable]
end
end
end