From 3d5627e1b97072d6c6919c2bda19e5fe20ff2af9 Mon Sep 17 00:00:00 2001 From: Sandro Date: Thu, 4 Feb 2021 12:56:56 +0100 Subject: [PATCH 1/2] fix for avatar in migration --- db/migrate/20210204114922_add_default_avatar.rb | 13 +++++++++++++ db/schema.rb | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20210204114922_add_default_avatar.rb diff --git a/db/migrate/20210204114922_add_default_avatar.rb b/db/migrate/20210204114922_add_default_avatar.rb new file mode 100644 index 0000000..32a2955 --- /dev/null +++ b/db/migrate/20210204114922_add_default_avatar.rb @@ -0,0 +1,13 @@ +class AddDefaultAvatar < ActiveRecord::Migration[6.0] + def up + User.all.each do |user| + next unless user.avatar.attached? + + user.avatar.attach( + io: File.open( + Rails.root.join('app/assets/images/default_avatar.png') + ), filename: 'default_avatar.png', content_type: 'image/png' + ) + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 61c27a8..61479fc 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_02_02_132517) do +ActiveRecord::Schema.define(version: 2021_02_04_114922) do create_table "active_storage_attachments", force: :cascade do |t| t.string "name", null: false From 3bef2e4b93b413bec1b50f7df712fd01eaaee066 Mon Sep 17 00:00:00 2001 From: Sandro Date: Thu, 4 Feb 2021 13:12:49 +0100 Subject: [PATCH 2/2] fixed for real now --- db/migrate/20210204114922_add_default_avatar.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/migrate/20210204114922_add_default_avatar.rb b/db/migrate/20210204114922_add_default_avatar.rb index 32a2955..968058b 100644 --- a/db/migrate/20210204114922_add_default_avatar.rb +++ b/db/migrate/20210204114922_add_default_avatar.rb @@ -1,13 +1,14 @@ class AddDefaultAvatar < ActiveRecord::Migration[6.0] def up User.all.each do |user| - next unless user.avatar.attached? + next if user.avatar.attached? user.avatar.attach( io: File.open( Rails.root.join('app/assets/images/default_avatar.png') ), filename: 'default_avatar.png', content_type: 'image/png' ) + user.save end end end