From 261d7dd0deb0bb4bada3f4fa86b13c8b6086edcd Mon Sep 17 00:00:00 2001 From: Rishabh Saxena Date: Thu, 11 Aug 2016 17:47:52 +0530 Subject: [PATCH] improve flash error collection improve views --- app/controllers/payments_controller.rb | 1 + .../ticket_purchases_controller.rb | 2 +- .../conference_registrations/show.html.haml | 26 +++++++++---------- app/views/payments/new.html.haml | 5 ---- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/app/controllers/payments_controller.rb b/app/controllers/payments_controller.rb index a86c5f66..5b1259d1 100644 --- a/app/controllers/payments_controller.rb +++ b/app/controllers/payments_controller.rb @@ -23,6 +23,7 @@ class PaymentsController < ApplicationController else @total_amount_to_pay = Ticket.total_price(@conference, current_user, paid: false) @unpaid_ticket_purchases = current_user.ticket_purchases.unpaid.by_conference(@conference) + flash[:error] = @payment.errors.full_messages.to_sentence + ' Please try again with correct credentials.' render :new end end diff --git a/app/controllers/ticket_purchases_controller.rb b/app/controllers/ticket_purchases_controller.rb index fb937dec..2d9d269b 100644 --- a/app/controllers/ticket_purchases_controller.rb +++ b/app/controllers/ticket_purchases_controller.rb @@ -4,7 +4,7 @@ class TicketPurchasesController < ApplicationController authorize_resource :conference_registrations, class: Registration def create - TicketPurchase.by_conference(@conference).unpaid.by_user(current_user).destroy_all + current_user.ticket_purchases.by_conference(@conference).unpaid.destroy_all message = TicketPurchase.purchase(@conference, current_user, params[:tickets][0]) if message.blank? if current_user.ticket_purchases.by_conference(@conference).unpaid.any? diff --git a/app/views/conference_registrations/show.html.haml b/app/views/conference_registrations/show.html.haml index 9debda28..1567475f 100644 --- a/app/views/conference_registrations/show.html.haml +++ b/app/views/conference_registrations/show.html.haml @@ -85,12 +85,12 @@ - if @conference.tickets.any? .row .col-md-12 - %h4 - %span.fa-stack - %i.fa.fa-square-o.fa-stack-2x - %i.fa.fa-ticket.fa-stack-1x - Ticket Purchases - -if @tickets.any? + -if @tickets.any? + %h4 + %span.fa-stack + %i.fa.fa-square-o.fa-stack-2x + %i.fa.fa-ticket.fa-stack-1x + Ticket Purchases = "(#{@tickets.first.price.symbol}#{humanized_money @total_price})" %ul .col-md-12 @@ -103,13 +103,13 @@ = tickets.first.price.symbol = humanized_money tickets.first.price %br - - if @tickets.any? - = link_to 'Buy more tickets', conference_tickets_path(@conference.short_title), class: "btn btn-default" - - else - You haven't bought any tickets. - = link_to 'Please buy some tickets to support us!', conference_tickets_path(@conference.short_title) - %p - (Your participation won't be valid without buying a ticket) + - if @tickets.any? + = link_to 'Buy more tickets', conference_tickets_path(@conference.short_title), class: "btn btn-default" + - else + You haven't bought any tickets. + = link_to 'Please buy some tickets to support us!', conference_tickets_path(@conference.short_title) + %p + (Your participation won't be valid without buying a ticket) .row .col-md-12 diff --git a/app/views/payments/new.html.haml b/app/views/payments/new.html.haml index 0f12bf34..0401f785 100644 --- a/app/views/payments/new.html.haml +++ b/app/views/payments/new.html.haml @@ -4,11 +4,6 @@ %h1 Payment Summary : = humanized_money_with_symbol @total_amount_to_pay - - if @payment.errors.any? - .alert.alert-danger - %ul - - @payment.errors.full_messages.each do |msg| - %li= msg .col-xs-8.col-xs-offset-2.well = render partial: 'payment' .row