Error display handling fixed for uploads
This commit is contained in:
parent
9e455f25eb
commit
169ad369e4
2 changed files with 28 additions and 26 deletions
|
|
@ -52,6 +52,8 @@ class PackagesController < ApplicationController
|
|||
return
|
||||
end
|
||||
|
||||
all_errors = []
|
||||
|
||||
params[:file].each do |img|
|
||||
# Log.log "Uploaded img=#{img.path}"
|
||||
new_screenshot = @package.screenshots.new(simage: img)
|
||||
|
|
@ -81,22 +83,22 @@ class PackagesController < ApplicationController
|
|||
|
||||
@valid_images.push new_screenshot
|
||||
else
|
||||
Log.log "Screenshot #{new_screenshot.image_file_name} invalid (#{new_screenshot.errors[:image]})."
|
||||
@invalid_images.push new_screenshot.original_filename
|
||||
errors = new_screenshot.errors[:simage]
|
||||
Log.log "Screenshot #{img.original_filename} invalid (#{errors})."
|
||||
#@invalid_images.push img.original_filename
|
||||
#raise
|
||||
all_errors << "Your file #{img.original_filename} #{errors.join(' and ')}."
|
||||
end
|
||||
end
|
||||
|
||||
errors = []
|
||||
@invalid_images.each do |image|
|
||||
# errors << "The image #{image.image_file_name} #{image.errors[:image].join(' and ')}."
|
||||
errors << "The file #{image} is not valid."
|
||||
flash[:error] = errors.join(" ")
|
||||
if all_errors
|
||||
flash[:error] = all_errors
|
||||
end
|
||||
|
||||
# Redirect back to upload form if all uploads were invalid
|
||||
unless @valid_images.any?
|
||||
Log.log "No valid images uploaded. Back to upload form."
|
||||
redirect_to(upload_path, error: errors) and return
|
||||
redirect_to(upload_path, error: all_errors) and return
|
||||
end
|
||||
|
||||
# Show a list of invalid uploads by default. Or redirect to the review page
|
||||
|
|
@ -234,21 +236,21 @@ class PackagesController < ApplicationController
|
|||
end
|
||||
|
||||
# Receive an anonymous report from a user to have a screenshot removed.
|
||||
def report_screenshot
|
||||
@screenshot = Screenshot.find(params[:id])
|
||||
# if verify_recaptcha
|
||||
@screenshot.delete_reason = params[:delete_reason]
|
||||
@screenshot.markedfordelete = true
|
||||
if @screenshot.valid?
|
||||
@screenshot.save!
|
||||
flash['notice'] = "Screenshot reported. The moderators will deal with it."
|
||||
else
|
||||
errors = @screenshot.errors.to_a.join(' and ')
|
||||
flash['alert'] = "Sorry. #{errors}"
|
||||
end
|
||||
# end
|
||||
redirect_back(fallback_location: package_path)
|
||||
end
|
||||
# def report_screenshot
|
||||
# @screenshot = Screenshot.find(params[:id])
|
||||
# # if verify_recaptcha
|
||||
# @screenshot.delete_reason = params[:delete_reason]
|
||||
# @screenshot.markedfordelete = true
|
||||
# if @screenshot.valid?
|
||||
# @screenshot.save!
|
||||
# flash['notice'] = "Screenshot reported. The moderators will deal with it."
|
||||
# else
|
||||
# errors = @screenshot.errors.to_a.join(' and ')
|
||||
# flash['alert'] = "Sorry. #{errors}"
|
||||
# end
|
||||
# # end
|
||||
# redirect_back(fallback_location: package_path)
|
||||
# end
|
||||
|
||||
# Show an HTML partial with reviews of this package from the Ubuntu API
|
||||
# def reviews
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@
|
|||
- next
|
||||
- when 'notice'
|
||||
.callout.warning.alert-callout-subtle.radius data-closable=true
|
||||
strong< = msg
|
||||
strong< = safe_join(msg, "<br />".html_safe)
|
||||
- when 'error'
|
||||
.callout.alert.alert-callout-subtle.radius data-closable=true
|
||||
strong< = msg
|
||||
strong< = safe_join(msg, "<br />".html_safe)
|
||||
- else
|
||||
.callout.primary.alert-callout-subtle.radius data-closable=true
|
||||
strong< = msg
|
||||
strong< = safe_join(msg, "<br />".html_safe)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue