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 end
def show def show
TicketPurchase.destroy_all(user_id: current_user.id, conference_id: @conference.id, paid: 'f') @total_price = Ticket.total_price(@conference, current_user, true)
@total_price = Ticket.total_price(@conference, current_user, 't')
@tickets = current_user.ticket_purchases.where(conference_id: @conference.id) @tickets = current_user.ticket_purchases.where(conference_id: @conference.id)
@ticket_payments = @tickets.group_by(&:payment_id) @ticket_payments = @tickets.group_by(&:payment_id)
end end

View file

@ -9,24 +9,22 @@ class PaymentsController < ApplicationController
end end
def new 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 end
def create def create
@payment = Payment.new(payment_params) @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) 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 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.' } redirect_to conference_conference_registrations_path(@conference.short_title), flash: { success: 'Thanks! You have purchased your tickets successfully.' }
else else
render 'new' render 'new'
end end
end end
end
private private

View file

@ -4,10 +4,10 @@ class TicketPurchasesController < ApplicationController
authorize_resource :conference_registrations, class: Registration authorize_resource :conference_registrations, class: Registration
def create 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]) message = TicketPurchase.purchase(@conference, current_user, params[:tickets][0])
if message.blank? 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.' redirect_to new_conference_payment_path, notice: 'Please pay here to purchase tickets.'
else else
redirect_to conference_conference_registration_path(@conference.short_title) redirect_to conference_conference_registration_path(@conference.short_title)

View file

@ -45,7 +45,7 @@ class TicketPurchase < ActiveRecord::Base
purchase = TicketPurchase.where(ticket_id: ticket.id, purchase = TicketPurchase.where(ticket_id: ticket.id,
conference_id: conference.id, conference_id: conference.id,
user_id: user.id, user_id: user.id,
paid: 'f').first paid: false).first
purchase.quantity = quantity if quantity > 0 purchase.quantity = quantity if quantity > 0
purchase purchase
@ -54,10 +54,10 @@ class TicketPurchase < ActiveRecord::Base
def self.update_paid_ticket_purchases(conference, user, payment) def self.update_paid_ticket_purchases(conference, user, payment)
paid_ticket_purchases = TicketPurchase.where(conference_id: conference.id, paid_ticket_purchases = TicketPurchase.where(conference_id: conference.id,
user_id: user.id, user_id: user.id,
paid: 'f') paid: false)
begin begin
paid_ticket_purchases.each do |ticket| paid_ticket_purchases.each do |ticket|
ticket.paid = 't' ticket.paid = true
ticket.payment_id = payment.id ticket.payment_id = payment.id
ticket.save ticket.save
end end