Skip to content

Error: private method `open' called for #<ActiveStorage::Attached::Many #127

@spacerobotTR

Description

@spacerobotTR

Not sure what I am doing wrong. I am using rails 6 and attempting to clone a record and it's attached uploads. Any ideas why this is generating this error?

Model:

class Compitem < ApplicationRecord
  belongs_to :user
  has_many_attached :uploads, dependent: :destroy
end

Copy method

  def copy
   @source = Compitem.find(params[:id])
   @source.deep_clone do |original, kopy|
      if kopy.is_a?(Compitem) && original.uploads.attached?
        original.uploads.open do |tempfile|
          kopy.uploads.attach({
            io: File.open(tempfile.path),
            filename: original.uploads.blob.filename,
            content_type: original.uploads.blob.content_type
          })
        end
      end
    end
   render 'new'
  end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions