LoginSignup
16
15

More than 5 years have passed since last update.

Railsのcarrierwaveでアップロード済みの画像をコピーする方法

Posted at

すでに、アップロード済みのorg_imageのavatarをnew_imageのavatarにコピーする場合。

org_image.rb
class OrgImage < ActiveRecord::Base
    mount_uploader :avatar, ImageUploader

    xxxxx
    xxxxx

end

new_image.rb
class NewImage < ActiveRecord::Base
    mount_uploader :avatar, ImageUploader

    xxxxx
    xxxxx

end

controller.rb


def image_copy
    org_image = OrgImage.find(id)
    new_image = NewImage.new
    new_image.avatar = org_image.avatar.file
    new_image.save
end

16
15
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
15