Skip to content

Commit 6463af5

Browse files
committed
flatten ifs in catalog_controller image processing
1 parent ce85853 commit 6463af5

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

app/controllers/catalog_controller.rb

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -534,31 +534,28 @@ def st_upload_image
534534

535535
err = false
536536
identify_catalog(params[:id])
537+
image_file = params.dig(:upload, :image)
537538
if params[:pressed]
538539
@record.picture = nil
539540
@record.save
540541
msg = _("Custom Image successfully removed")
541-
elsif params[:upload] && params[:upload][:image] &&
542-
params[:upload][:image].respond_to?(:read)
543-
ext = params[:upload][:image].original_filename.split(".").last.downcase
544-
if !valid_image_file?(params[:upload][:image])
545-
msg = _("Custom Image must be a .png or .jpg file")
546-
err = true
547-
else
548-
picture = {:content => params[:upload][:image].read,
549-
:extension => ext}
550-
if @record.picture.nil?
551-
@record.picture = Picture.new(picture)
552-
else
553-
@record.picture.update(picture)
554-
end
555-
@record.save
556-
msg = _("Custom Image file \"%{name}\" successfully uploaded") %
557-
{:name => params[:upload][:image].original_filename}
558-
end
559-
else
542+
elsif !image_file&.respond_to?(:read)
560543
msg = _("Use the Choose file button to locate a .png or .jpg image file")
561544
err = true
545+
elsif !valid_image_file?(image_file)
546+
msg = _("Custom Image must be a .png or .jpg file")
547+
err = true
548+
else
549+
ext = image_file.original_filename.split(".").last.downcase
550+
picture = {:content => image_file.read, :extension => ext}
551+
if @record.picture.nil?
552+
@record.picture = Picture.new(picture)
553+
else
554+
@record.picture.update(picture)
555+
end
556+
@record.save
557+
msg = _("Custom Image file \"%{name}\" successfully uploaded") %
558+
{:name => image_file.original_filename}
562559
end
563560
params[:id] = x_build_node_id(@record) # Get the tree node id
564561
add_flash(msg, err == true ? :error : nil)

0 commit comments

Comments
 (0)