1
0
Fork 0
forked from OpenNeo/impress

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.
This commit is contained in:
Emi Matchu 2014-09-13 14:16:50 -05:00
parent 485a679f5e
commit 51700a7386
2 changed files with 6 additions and 2 deletions

View file

@ -28,7 +28,7 @@ class DonationsController < ApplicationController
@features.each(&:save!)
end
rescue ActiveRecord::RecordInvalid
flash[:error] = "Couldn't save donation details. Do those outfits exist?"
flash[:alert] = "Couldn't save donation details. Do those outfits exist?"
redirect_to @donation
else
flash[:success] = 'Donation details saved! ' +

View file

@ -2,7 +2,7 @@ class DonationFeature < ActiveRecord::Base
belongs_to :donation
belongs_to :outfit
validates :outfit, presence: true, if: :outfit_id?
validates :outfit, presence: true, if: :outfit_id_present?
delegate :donor_name, to: :donation
@ -13,4 +13,8 @@ class DonationFeature < ActiveRecord::Base
def outfit_url=(outfit_url)
self.outfit_id = outfit_url.split('/').last rescue nil
end
def outfit_id_present?
outfit_id.present?
end
end