Last active
October 30, 2022 22:04
-
-
Save michalkorzawski/bf487868d1cd48be02e1aa55e8dc9b3e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/controllers/records_controller.rb | |
def some_method | |
... business logic ... | |
attaching_images = params[:record][:images].presence | |
if attaching_images | |
attaching_images = attaching_images.map do |im| | |
tempfile = ImageConverter.new(tempfile: im.tempfile, width: 1200).call | |
ActionDispatch::Http::UploadedFile.new( | |
{ | |
filename: "#{im.original_filename.split('.').first}.jpg", | |
tempfile: tempfile, | |
type: 'image/jpg', | |
head: "Content-Disposition: form-data; name=\"property[images][]\"; filename=\"#{im.original_filename.split('.').first}.jpg\"\r\nContent-Type: image/jpg\r\n" | |
} | |
) | |
end | |
end | |
if record.new(permitted_params.merge(images: attaching_images)).save | |
... | |
else | |
... | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment