Added amount check for payments#new
This commit is contained in:
parent
72afae6f2f
commit
3b27a2a8fb
1 changed files with 3 additions and 6 deletions
|
|
@ -3,7 +3,6 @@ class PaymentsController < ApplicationController
|
||||||
load_and_authorize_resource
|
load_and_authorize_resource
|
||||||
load_resource :conference, find_by: :short_title
|
load_resource :conference, find_by: :short_title
|
||||||
authorize_resource :conference_registrations, class: Registration
|
authorize_resource :conference_registrations, class: Registration
|
||||||
before_action :check_amount, only: [:new]
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@payments = current_user.payments
|
@payments = current_user.payments
|
||||||
|
|
@ -11,6 +10,9 @@ class PaymentsController < ApplicationController
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@total_amount_to_pay = Ticket.total_price(@conference, current_user, paid: false)
|
@total_amount_to_pay = Ticket.total_price(@conference, current_user, paid: false)
|
||||||
|
if @total_amount_to_pay.zero?
|
||||||
|
raise CanCan::AccessDenied.new('Nothing to pay for!', :new, Payment)
|
||||||
|
end
|
||||||
@unpaid_ticket_purchases = current_user.ticket_purchases.unpaid.by_conference(@conference)
|
@unpaid_ticket_purchases = current_user.ticket_purchases.unpaid.by_conference(@conference)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -29,11 +31,6 @@ class PaymentsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_amount
|
|
||||||
@total_amount_to_pay = Ticket.total_price(@conference, current_user, paid: false)
|
|
||||||
redirect_to root_path if @total_amount_to_pay.zero?
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def payment_params
|
def payment_params
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue