forked from OpenNeo/impress
Matchu
51700a7386
In particular, outfit_id == 0 would cause outfit_id? to return false, so it wouldn't run the outfit presence validation, so /donations/features would try to load outfit #0 and fail. Also, flash[:alert] instead of flash[:error] when outfit_id is bad.
20 lines
448 B
Ruby
20 lines
448 B
Ruby
class DonationFeature < ActiveRecord::Base
|
|
belongs_to :donation
|
|
belongs_to :outfit
|
|
|
|
validates :outfit, presence: true, if: :outfit_id_present?
|
|
|
|
delegate :donor_name, to: :donation
|
|
|
|
def as_json(options={})
|
|
{donor_name: donor_name, outfit_image_url: outfit.image.medium.url}
|
|
end
|
|
|
|
def outfit_url=(outfit_url)
|
|
self.outfit_id = outfit_url.split('/').last rescue nil
|
|
end
|
|
|
|
def outfit_id_present?
|
|
outfit_id.present?
|
|
end
|
|
end
|