1
0
Fork 0
forked from OpenNeo/impress
impress/app/controllers/donations_controller.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

39 lines
1.1 KiB
Ruby

class DonationsController < ApplicationController
def create
@campaign = Campaign.current
@donation = Donation.create_from_charge(
@campaign, current_user, params[:donation])
redirect_to @donation
end
def show
@donation = Donation.from_param(params[:id])
@features = @donation.features
@outfits = current_user.outfits.wardrobe_order if user_signed_in?
end
def update
@donation = Donation.from_param(params[:id])
@donation.update_attributes params[:donation]
feature_params = params[:feature] || {}
@features = @donation.features.find(feature_params.keys)
@features.each do |feature|
feature.outfit_url = feature_params[feature.id.to_s][:outfit_url]
end
begin
Donation.transaction do
@donation.save!
@features.each(&:save!)
end
rescue ActiveRecord::RecordInvalid
flash[:alert] = "Couldn't save donation details. Do those outfits exist?"
redirect_to @donation
else
flash[:success] = 'Donation details saved! ' +
'Also, have we thanked you yet today? Thank you!'
redirect_to @donation
end
end
end