2014-08-28 15:21:05 +02:00
|
|
|
class TicketPurchasesController < ApplicationController
|
2014-11-06 14:58:51 +01:00
|
|
|
before_filter :authenticate_user!
|
2014-08-28 15:21:05 +02:00
|
|
|
load_resource :conference, find_by: :short_title
|
|
|
|
|
authorize_resource :conference_registrations, class: Registration
|
|
|
|
|
|
|
|
|
|
def create
|
|
|
|
|
message = TicketPurchase.purchase(@conference, current_user, params[:tickets][0])
|
|
|
|
|
if message.blank?
|
2014-12-05 16:04:34 +01:00
|
|
|
if current_user.ticket_purchases.any?
|
2016-07-05 00:10:18 +05:30
|
|
|
redirect_to conference_conference_registration_path(@conference.short_title),
|
2014-12-05 16:04:34 +01:00
|
|
|
notice: "Thank you for supporting #{@conference.title} by purchasing a ticket."
|
|
|
|
|
else
|
2016-07-05 00:10:18 +05:30
|
|
|
redirect_to conference_conference_registration_path(@conference.short_title)
|
2014-12-05 16:04:34 +01:00
|
|
|
end
|
2014-08-28 15:21:05 +02:00
|
|
|
else
|
2016-07-05 00:10:18 +05:30
|
|
|
redirect_to conference_conference_registration_path(@conference.short_title),
|
2016-03-16 11:20:56 +05:30
|
|
|
error: "Oops, something went wrong with your purchase! #{message}"
|
2014-08-28 15:21:05 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def destroy
|
2014-12-05 16:04:34 +01:00
|
|
|
@ticket_purchases = current_user.ticket_purchases.find(params[:id])
|
2014-08-28 15:21:05 +02:00
|
|
|
if @ticket_purchases.destroy
|
2016-07-05 00:10:18 +05:30
|
|
|
redirect_to conference_conference_registration_path(@conference.short_title),
|
2014-09-02 23:28:23 +03:00
|
|
|
notice: 'Ticket successfully deleted.'
|
2014-08-28 15:21:05 +02:00
|
|
|
else
|
2016-07-05 00:10:18 +05:30
|
|
|
redirect_to conference_conference_registration_path(@conference.short_title),
|
2016-03-16 11:20:56 +05:30
|
|
|
error: 'An error prohibited deleting your purchase! '\
|
2014-08-28 15:21:05 +02:00
|
|
|
"#{@ticket_purchases.errors.full_messages.join('. ')}."
|
|
|
|
|
end
|
|
|
|
|
end
|
2015-10-28 18:05:15 +02:00
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def ticket_purchase_params
|
|
|
|
|
params.require(:ticket_purchase).permit(:ticket_id, :user_id, :conference_id, :quantity)
|
|
|
|
|
end
|
2014-08-28 15:21:05 +02:00
|
|
|
end
|