From 1894cea9752736d049401a4dc4988c9fe29ed8fa Mon Sep 17 00:00:00 2001 From: Rishabh Saxena Date: Wed, 27 Jul 2016 19:40:21 +0530 Subject: [PATCH] modify ticket purchases view --- app/controllers/ticket_purchases_controller.rb | 18 +++--------------- app/views/tickets/_ticket.html.haml | 6 +----- app/views/tickets/index.html.haml | 11 +++++------ 3 files changed, 9 insertions(+), 26 deletions(-) diff --git a/app/controllers/ticket_purchases_controller.rb b/app/controllers/ticket_purchases_controller.rb index 30d24d82..43f6d09a 100644 --- a/app/controllers/ticket_purchases_controller.rb +++ b/app/controllers/ticket_purchases_controller.rb @@ -4,11 +4,11 @@ class TicketPurchasesController < ApplicationController authorize_resource :conference_registrations, class: Registration def create + TicketPurchase.by_conference(@conference).unpaid.by_user(current_user).destroy_all message = TicketPurchase.purchase(@conference, current_user, params[:tickets][0]) if message.blank? - if current_user.ticket_purchases.any? - redirect_to conference_conference_registration_path(@conference.short_title), - notice: "Thank you for supporting #{@conference.title} by purchasing a ticket." + if current_user.ticket_purchases.by_conference(@conference).unpaid.any? + redirect_to new_conference_payment_path, notice: 'Please pay here to purchase tickets.' else redirect_to conference_conference_registration_path(@conference.short_title) end @@ -18,18 +18,6 @@ class TicketPurchasesController < ApplicationController end end - def destroy - @ticket_purchases = current_user.ticket_purchases.find(params[:id]) - if @ticket_purchases.destroy - redirect_to conference_conference_registration_path(@conference.short_title), - notice: 'Ticket successfully deleted.' - else - redirect_to conference_conference_registration_path(@conference.short_title), - error: 'An error prohibited deleting your purchase! '\ - "#{@ticket_purchases.errors.full_messages.join('. ')}." - end - end - private def ticket_purchase_params diff --git a/app/views/tickets/_ticket.html.haml b/app/views/tickets/_ticket.html.haml index 1a93f46b..e3985773 100644 --- a/app/views/tickets/_ticket.html.haml +++ b/app/views/tickets/_ticket.html.haml @@ -8,12 +8,8 @@ - unless ticket.description.blank? = markdown(ticket.description) %td.col-sm-1.col-md-1 - - if ticket.bought?(current_user) - = text_field_tag("tickets[][#{ticket.id}]", ticket.quantity_bought_by(current_user), + = text_field_tag("tickets[][#{ticket.id}]", 0, type: 'number', min: 0, class: "form-control quantity", 'data-id' => ticket.id) - - else - = text_field_tag("tickets[][#{ticket.id}]", 0, type: 'number', min: 0, - class: "form-control quantity", 'data-id' => ticket.id) %td.col-sm-1.col-md-1.text-center = ticket.price.symbol %span{id: "price_#{ticket.id}"} diff --git a/app/views/tickets/index.html.haml b/app/views/tickets/index.html.haml index fbc2df7c..8f80e1ac 100644 --- a/app/views/tickets/index.html.haml +++ b/app/views/tickets/index.html.haml @@ -5,10 +5,10 @@ %h1 Tickets %p.lead - If you like, support + Please choose your tickets for %strong = @conference.title - by buying a ticket* + here* =form_tag(conference_ticket_purchases_path, method: :post) do |f| %table.table.table-hover %thead @@ -35,12 +35,11 @@ .pull-right .btn-group-vertical = button_tag(type: 'submit', class: 'btn btn-success btn-lg') do - Support + Continue %i.fa.fa-shopping-cart - = link_to 'Continue without a Ticket!', conference_conference_registration_path(@conference.short_title), - class: 'btn btn-danger btn-sm' + = link_to 'Cancel registration', conference_conference_registration_path(@conference.short_title), method: :delete, class: 'btn btn-danger btn-sm' .row .col-md-13 %p.text-muted.text-center %small - * Buying a ticket is not mandatory. Checkout will be at the conference registration. + * Buying a ticket is mandatory. Your registration will not complete until you buy a ticket.