impress/app/models/donation_feature.rb
Matchu 51700a7386 better donation feature outfit validation
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.
2014-09-13 14:16:50 -05:00

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