modify ticket purchases view

This commit is contained in:
Rishabh Saxena 2016-07-27 19:40:21 +05:30
parent 92dc0edff2
commit 1894cea975
3 changed files with 9 additions and 26 deletions

View file

@ -4,11 +4,11 @@ class TicketPurchasesController < ApplicationController
authorize_resource :conference_registrations, class: Registration
def create
TicketPurchase.by_conference(@conference).unpaid.by_user(current_user).destroy_all
message = TicketPurchase.purchase(@conference, current_user, params[:tickets][0])
if message.blank?
if current_user.ticket_purchases.any?
redirect_to conference_conference_registration_path(@conference.short_title),
notice: "Thank you for supporting #{@conference.title} by purchasing a ticket."
if current_user.ticket_purchases.by_conference(@conference).unpaid.any?
redirect_to new_conference_payment_path, notice: 'Please pay here to purchase tickets.'
else
redirect_to conference_conference_registration_path(@conference.short_title)
end
@ -18,18 +18,6 @@ class TicketPurchasesController < ApplicationController
end
end
def destroy
@ticket_purchases = current_user.ticket_purchases.find(params[:id])
if @ticket_purchases.destroy
redirect_to conference_conference_registration_path(@conference.short_title),
notice: 'Ticket successfully deleted.'
else
redirect_to conference_conference_registration_path(@conference.short_title),
error: 'An error prohibited deleting your purchase! '\
"#{@ticket_purchases.errors.full_messages.join('. ')}."
end
end
private
def ticket_purchase_params