2023-08-02 16:05:02 -07:00
|
|
|
class DonationFeature < ApplicationRecord
|
2014-09-09 21:16:02 -07:00
|
|
|
belongs_to :donation
|
|
|
|
belongs_to :outfit
|
|
|
|
|
2014-09-13 12:16:50 -07:00
|
|
|
validates :outfit, presence: true, if: :outfit_id_present?
|
2014-09-09 21:16:02 -07:00
|
|
|
|
2014-09-10 13:38:26 -07:00
|
|
|
delegate :donor_name, to: :donation
|
|
|
|
|
|
|
|
def as_json(options={})
|
2015-02-25 11:42:35 -08:00
|
|
|
{donor_name: donor_name, outfit_image_url: outfit_image_url}
|
2014-09-10 13:38:26 -07:00
|
|
|
end
|
|
|
|
|
2014-09-09 21:16:02 -07:00
|
|
|
def outfit_url=(outfit_url)
|
|
|
|
self.outfit_id = outfit_url.split('/').last rescue nil
|
|
|
|
end
|
2014-09-13 12:16:50 -07:00
|
|
|
|
|
|
|
def outfit_id_present?
|
|
|
|
outfit_id.present?
|
|
|
|
end
|
2015-02-25 11:42:35 -08:00
|
|
|
|
|
|
|
def outfit_image_url
|
|
|
|
outfit && outfit.image ? outfit.image.medium.url : nil
|
|
|
|
end
|
2014-09-09 21:16:02 -07:00
|
|
|
end
|