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:
parent
485a679f5e
commit
51700a7386
2 changed files with 6 additions and 2 deletions
|
@ -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! ' +
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue