I've got below implementation for my controller and show action which implements MiniMagick
gem. I've just wondering is there any better way to write it down? If block in a separate, private method maybe?
def show
identification_document = IdentificationDocument.find(params[:id])
authorize identification_document
return unless identification_document
if params.has_key?(:thumbnail)
document = identification_document.id_document
image = MiniMagick::Image.read(document.file.read)
image.resize("50x60")
scaled_image_bytes = image.to_blob
send_data(scaled_image_bytes, filename: identification_document.file_name)
else
send_data(identification_document.id_document.file.read, filename: identification_document.file_name)
end
end