2020-01-27 17:10:29 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Admin defined assets (like PDF or images uploaded)
|
2020-03-25 10:16:47 +01:00
|
|
|
class CustomAsset < ApplicationRecord
|
2016-03-23 18:39:41 +01:00
|
|
|
has_one :custom_asset_file, as: :viewable, dependent: :destroy
|
|
|
|
accepts_nested_attributes_for :custom_asset_file, allow_destroy: true
|
|
|
|
|
2018-12-03 15:10:04 +01:00
|
|
|
# static method to retrieve the attachment URL of the custom asset
|
2016-03-23 18:39:41 +01:00
|
|
|
def self.get_url(name)
|
|
|
|
asset = CustomAsset.find_by(name: name)
|
2018-12-03 15:10:04 +01:00
|
|
|
asset&.custom_asset_file&.attachment_url
|
2016-03-23 18:39:41 +01:00
|
|
|
end
|
2016-05-18 16:15:54 +02:00
|
|
|
|
2020-03-24 16:45:27 +01:00
|
|
|
after_update :update_stylesheet if :saved_change_to_viewable?
|
2016-05-18 16:15:54 +02:00
|
|
|
|
|
|
|
def update_stylesheet
|
2020-01-27 17:10:29 +01:00
|
|
|
Stylesheet.theme.rebuild! if %w[profile-image-file].include? name
|
2016-05-18 16:15:54 +02:00
|
|
|
end
|
2016-03-23 18:39:41 +01:00
|
|
|
end
|