impress/app/controllers/donations_controller.rb

40 lines
1.1 KiB
Ruby
Raw Normal View History

2014-09-09 19:06:38 -07:00
class DonationsController < ApplicationController
def create
2014-09-11 15:40:37 -07:00
@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])
2014-09-09 21:16:02 -07:00
@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]
2014-09-09 21:16:02 -07:00
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?"
2014-09-09 21:16:02 -07:00
redirect_to @donation
else
flash[:success] = 'Donation details saved! ' +
'Also, have we thanked you yet today? Thank you!'
redirect_to @donation
end
2014-09-09 19:06:38 -07:00
end
end