add more explanatory true/false values

This commit is contained in:
Rishabh Saxena 2016-07-05 16:39:38 +05:30
parent f202c6b93b
commit c0c84b9dbf
4 changed files with 14 additions and 17 deletions

View file

@ -28,8 +28,7 @@ class ConferenceRegistrationsController < ApplicationController
end
def show
TicketPurchase.destroy_all(user_id: current_user.id, conference_id: @conference.id, paid: 'f')
@total_price = Ticket.total_price(@conference, current_user, 't')
@total_price = Ticket.total_price(@conference, current_user, true)
@tickets = current_user.ticket_purchases.where(conference_id: @conference.id)
@ticket_payments = @tickets.group_by(&:payment_id)
end

View file

@ -9,22 +9,20 @@ class PaymentsController < ApplicationController
end
def new
@total_amount_to_pay = Ticket.total_price(@conference, current_user, 'f')
@total_amount_to_pay = Ticket.total_price(@conference, current_user, false)
end
def create
@payment = Payment.new(payment_params)
@total_amount_to_pay = Ticket.total_price(@conference, current_user, 'f')
@total_amount_to_pay = Ticket.total_price(@conference, current_user, false)
if @payment.valid? && @payment.purchase(current_user, @conference, price_in_cents)
@payment.save
@update_ticket_purchases = TicketPurchase.update_paid_ticket_purchases(@conference, current_user, @payment)
end
if @payment.save
redirect_to conference_conference_registrations_path(@conference.short_title), flash: { success: 'Thanks! You have purchased your tickets successfully.' }
else
render 'new'
if @payment.save
@update_ticket_purchases = TicketPurchase.update_paid_ticket_purchases(@conference, current_user, @payment)
redirect_to conference_conference_registrations_path(@conference.short_title), flash: { success: 'Thanks! You have purchased your tickets successfully.' }
else
render 'new'
end
end
end

View file

@ -4,10 +4,10 @@ class TicketPurchasesController < ApplicationController
authorize_resource :conference_registrations, class: Registration
def create
TicketPurchase.destroy_all(user_id: current_user.id, conference_id: @conference.id, paid: 'f')
TicketPurchase.destroy_all(user_id: current_user.id, conference_id: @conference.id, paid: false)
message = TicketPurchase.purchase(@conference, current_user, params[:tickets][0])
if message.blank?
if current_user.ticket_purchases.where(paid: 'f').any?
if current_user.ticket_purchases.where(paid: false).any?
redirect_to new_conference_payment_path, notice: 'Please pay here to purchase tickets.'
else
redirect_to conference_conference_registration_path(@conference.short_title)