add more explanatory true/false values
This commit is contained in:
parent
f202c6b93b
commit
c0c84b9dbf
4 changed files with 14 additions and 17 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ class TicketPurchase < ActiveRecord::Base
|
|||
purchase = TicketPurchase.where(ticket_id: ticket.id,
|
||||
conference_id: conference.id,
|
||||
user_id: user.id,
|
||||
paid: 'f').first
|
||||
paid: false).first
|
||||
|
||||
purchase.quantity = quantity if quantity > 0
|
||||
purchase
|
||||
|
|
@ -54,10 +54,10 @@ class TicketPurchase < ActiveRecord::Base
|
|||
def self.update_paid_ticket_purchases(conference, user, payment)
|
||||
paid_ticket_purchases = TicketPurchase.where(conference_id: conference.id,
|
||||
user_id: user.id,
|
||||
paid: 'f')
|
||||
paid: false)
|
||||
begin
|
||||
paid_ticket_purchases.each do |ticket|
|
||||
ticket.paid = 't'
|
||||
ticket.paid = true
|
||||
ticket.payment_id = payment.id
|
||||
ticket.save
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue