Skip to content

Instantly share code, notes, and snippets.

@michalkorzawski
Last active October 30, 2022 22:04
Show Gist options
  • Select an option

  • Save michalkorzawski/bf487868d1cd48be02e1aa55e8dc9b3e to your computer and use it in GitHub Desktop.

Select an option

Save michalkorzawski/bf487868d1cd48be02e1aa55e8dc9b3e to your computer and use it in GitHub Desktop.

Revisions

  1. michalkorzawski revised this gist Oct 30, 2022. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions records_controller.rb
    Original file line number Diff line number Diff line change
    @@ -3,14 +3,14 @@
    def some_method
    ... business logic ...

    @attaching_images = params[:record][:images].presence
    if @attaching_images
    @attaching_images = @attaching_images.map do |im|
    io = ImageConverter.new(tempfile: im.tempfile, width: 1200).call
    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: io,
    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"
    }
  2. michalkorzawski revised this gist Oct 24, 2022. 1 changed file with 23 additions and 13 deletions.
    36 changes: 23 additions & 13 deletions records_controller.rb
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,26 @@
    # records_controller.rb
    # app/controllers/records_controller.rb

    @attaching_images = params[:record][:images].presence
    if @attaching_images
    @attaching_images = @attaching_images.map do |im|
    io = ImageConverter.new(tempfile: im.tempfile, width: 1200).call
    ActionDispatch::Http::UploadedFile.new(
    {
    filename: "#{im.original_filename.split('.').first}.jpg",
    tempfile: io,
    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"
    }
    )
    def some_method
    ... business logic ...

    @attaching_images = params[:record][:images].presence
    if @attaching_images
    @attaching_images = @attaching_images.map do |im|
    io = ImageConverter.new(tempfile: im.tempfile, width: 1200).call
    ActionDispatch::Http::UploadedFile.new(
    {
    filename: "#{im.original_filename.split('.').first}.jpg",
    tempfile: io,
    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
  3. michalkorzawski revised this gist Oct 23, 2022. No changes.
  4. michalkorzawski created this gist Oct 23, 2022.
    16 changes: 16 additions & 0 deletions records_controller.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    # records_controller.rb

    @attaching_images = params[:record][:images].presence
    if @attaching_images
    @attaching_images = @attaching_images.map do |im|
    io = ImageConverter.new(tempfile: im.tempfile, width: 1200).call
    ActionDispatch::Http::UploadedFile.new(
    {
    filename: "#{im.original_filename.split('.').first}.jpg",
    tempfile: io,
    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