Make additional updates to ActiveStorage

This commit is contained in:
Eric 2020-05-18 16:05:25 -05:00
parent a7cb3419cd
commit 34882dc099
5 changed files with 10 additions and 18 deletions

View file

@ -51,7 +51,7 @@ class CampaignsController < ApplicationController
@peer_to_peer_campaign_param = @campaign.id
end
@campaign_background_image = FetchBackgroundImage.with_model(@campaign)
@campaign_background_image = @campaign.background_image.attached? && url_for(@campaign.background_image_by_size(:normal))
end
def activities

View file

@ -19,7 +19,7 @@ class EventsController < ApplicationController
def show
@event = params[:event_slug] ? Event.find_by_slug!(params[:event_slug]) : Event.find_by_id!(params[:id])
@event_background_image = FetchBackgroundImage.with_model(@event)
@event_background_image = @event.background_image.attached? && url_for(@event.background_image_by_size(:normal))
@nonprofit = @event.nonprofit
if @event.deleted && !current_event_editor?
redirect_to nonprofit_path(current_nonprofit)
@ -71,7 +71,7 @@ class EventsController < ApplicationController
def stats
@event = current_event
@url = Format::Url.concat(root_url, @event.url)
@event_background_image = FetchBackgroundImage.with_model(@event)
@event_background_image = @event.background_image.attached? && url_for(@event.background_image_by_size(:normal))
render layout: 'layouts/embed'
end

View file

@ -24,17 +24,17 @@ module CreatePeerToPeerCampaign
campaign.save
begin
campaign.update_attribute(:main_image, parent_campaign.main_image) if parent_campaign.main_image
campaign.main_image.attach(parent_campaign.main_image.blob) if parent_campaign.main_image.attached?
rescue StandardError
AWS::S3::Errors::NoSuchKey
end
begin
campaign.update_attribute(:background_image, parent_campaign.background_image) if parent_campaign.background_image
campaign.background_image.attach(parent_campaign.background_image.blob) if parent_campaign.background_image.attached?
rescue StandardError
AWS::S3::Errors::NoSuchKey
end
begin
campaign.update_attribute(:banner_image, parent_campaign.banner_image) if parent_campaign.banner_image
campaign.banner_image.attach(parent_campaign.banner_image.blob) if parent_campaign.banner_image.attached?
rescue StandardError
AWS::S3::Errors::NoSuchKey
end

View file

@ -1,8 +0,0 @@
# frozen_string_literal: true
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
module FetchBackgroundImage
def self.with_model(model)
return model.background_image_url(:normal) unless model.background_image.file.nil?
end
end

View file

@ -30,13 +30,13 @@ module InsertDuplicate
dupe.save!
begin
dupe.update_attribute(:main_image, campaign.main_image) if campaign.main_image
dupe.main_image.attach(campaign.main_image.blob) if campaign.main_image.attached?
rescue StandardError
AWS::S3::Errors::NoSuchKey
end
begin
dupe.update_attribute(:background_image, campaign.background_image) if campaign.background_image
dupe.background_image.attach(campaign.background_image.blob) if campaign.background_image.attached?
rescue StandardError
AWS::S3::Errors::NoSuchKey
end
@ -84,13 +84,13 @@ module InsertDuplicate
dupe.save!
begin
dupe.update_attribute(:main_image, event.main_image) if event.main_image
dupe.main_image.attach(event.main_image.blob) if event.main_image.attached?
rescue StandardError
AWS::S3::Errors::NoSuchKey
end
begin
dupe.update_attribute(:background_image, event.background_image) if event.background_image
dupe.background_image.attach( event.background_image.blob) if event.background_image.attached?
rescue StandardError
AWS::S3::Errors::NoSuchKey
end