From 2e0a3a6c0303177f13fe69e240fc9ec1bfbce935 Mon Sep 17 00:00:00 2001 From: Eric Date: Fri, 15 May 2020 12:32:47 -0500 Subject: [PATCH] Create default image attachments for all models --- app/models/campaign.rb | 3 +++ app/models/event.rb | 6 ++++++ app/models/nonprofit.rb | 12 +++++++++++- app/models/profile.rb | 2 ++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/models/campaign.rb b/app/models/campaign.rb index 1ca69f57..fc2d3ed1 100644 --- a/app/models/campaign.rb +++ b/app/models/campaign.rb @@ -58,6 +58,9 @@ class Campaign < ApplicationRecord has_one_attached_with_sizes(:main_image, {normal: [524, 360], thumb: [180,150]}) has_one_attached_with_sizes(:background_image, {normal: [1000, 600]}) + has_one_attached_with_default(:main_image, Image::DefaultProfileUrl, + filename: "main_image_#{SecureRandom.uuid}#{Pathname.new(Image::DefaultProfileUrl).extname}") + has_many :donations has_many :charges, through: :donations has_many :payments, through: :donations, source: 'payment' diff --git a/app/models/event.rb b/app/models/event.rb index 6953997b..1e53eca2 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -67,6 +67,12 @@ class Event < ApplicationRecord has_one_attached_with_sizes :main_image, {normal: 400, thumb: 100} has_one_attached_with_sizes :background_image, {normal: [1000, 600]} + + has_one_attached_with_default(:main_image, Image::DefaultProfileUrl, + filename: "main_image_#{SecureRandom.uuid}#{Pathname.new(Image::DefaultProfileUrl).extname}") + + has_one_attached_with_default(:background_image, Image::DefaultCampaignUrl, + filename: "background_image_#{SecureRandom.uuid}#{Pathname.new(Image::DefaultCampaignUrl).extname}") scope :not_deleted, -> { where(deleted: [nil, false]) } diff --git a/app/models/nonprofit.rb b/app/models/nonprofit.rb index d85b58e7..c1029141 100755 --- a/app/models/nonprofit.rb +++ b/app/models/nonprofit.rb @@ -111,7 +111,17 @@ class Nonprofit < ApplicationRecord has_one_attached_with_sizes(:second_image, {nonprofit_carousel: [590, 338], thumb: [188, 120], thumb_explore: [100, 100]}) has_one_attached_with_sizes(:third_image, {nonprofit_carousel: [590, 338], thumb: [188, 120], thumb_explore: [100, 100]}) - + has_one_attached_with_default(:logo, Image::DefaultProfileUrl, + filename: "logo_#{SecureRandom.uuid}#{Pathname.new(Image::DefaultProfileUrl).extname}") + has_one_attached_with_default(:background_image, Image::DefaultNonprofitUrl, + filename: "background_image_#{SecureRandom.uuid}#{Pathname.new(Image::DefaultNonprofitUrl).extname}") + has_one_attached_with_default(:main_image, Image::DefaultProfileUrl, + filename: "main_image_#{SecureRandom.uuid}#{Pathname.new(Image::DefaultProfileUrl).extname}") + has_one_attached_with_default(:second_image, Image::DefaultProfileUrl, + filename: "second_image_#{SecureRandom.uuid}#{Pathname.new(Image::DefaultProfileUrl).extname}") + has_one_attached_with_default(:third_image, Image::DefaultProfileUrl, + filename: "third_image_#{SecureRandom.uuid}#{Pathname.new(Image::DefaultProfileUrl).extname}") + serialize :achievements, Array serialize :categories, Array diff --git a/app/models/profile.rb b/app/models/profile.rb index a8ab05b8..d15490cc 100755 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -28,6 +28,8 @@ class Profile < ApplicationRecord has_one_attached :picture has_one_attached_with_sizes(:picture, {normal: 150, medium:100, tiny: 50}) + has_one_attached_with_default(:picture, Image::DefaultProfileUrl, + filename: "picture_#{SecureRandom.uuid}#{Pathname.new(Image::DefaultProfileUrl).extname}") belongs_to :user has_many :activities # Activities this profile has created