From 88a6b2769bae1080a1803f59e8a27b599e3498b4 Mon Sep 17 00:00:00 2001 From: nasia Date: Tue, 29 Aug 2017 16:20:21 +0300 Subject: [PATCH] Remove nil hash objects --- app/controllers/admin/sponsors_controller.rb | 5 +- app/views/admin/sponsors/index.html.haml | 70 ++++++++++---------- app/views/admin/sponsors/show.html.haml | 2 +- 3 files changed, 41 insertions(+), 36 deletions(-) diff --git a/app/controllers/admin/sponsors_controller.rb b/app/controllers/admin/sponsors_controller.rb index 0d99e807..8bb598d6 100644 --- a/app/controllers/admin/sponsors_controller.rb +++ b/app/controllers/admin/sponsors_controller.rb @@ -9,12 +9,15 @@ module Admin end def show + @sponsor.swag.reject! { |_key, value| value[:type].blank? || value[:quantity].blank? } + @sponsor.swag_transportation.reject! { |_key, value| value[:carrier_name].blank? || value[:tracking_number].blank? || value[:boxes].blank? } @sponsor.swag_index = @sponsor.swag.length @sponsor.carrier_index = @sponsor.swag_transportation.length end def edit - @sponsor.swag = @sponsor.swag + @sponsor.swag.reject! { |_key, value| value[:type].blank? || value[:quantity].blank? } + @sponsor.swag_transportation.reject! { |_key, value| value[:carrier_name].blank? || value[:tracking_number].blank? } @sponsor.swag_index = @sponsor.swag.length @sponsor.carrier_index = @sponsor.swag_transportation.length end diff --git a/app/views/admin/sponsors/index.html.haml b/app/views/admin/sponsors/index.html.haml index 64366320..d0cbfbea 100644 --- a/app/views/admin/sponsors/index.html.haml +++ b/app/views/admin/sponsors/index.html.haml @@ -92,13 +92,14 @@ - else %span.fa.fa-times.text-danger %td - - if sponsor.has_swag + - if sponsor.swag.length > 0 - sponsor.swag.each do |key, value| - = value[:type] - ( - = value[:quantity] - ) - %br + - unless value[:type].blank? + = value[:type] + ( + = value[:quantity] + ) + %br %td = check_box_tag @conference.short_title, sponsor.id, sponsor.swag_received, @@ -163,7 +164,7 @@ = link_to 'Cancel', cancel_admin_conference_sponsor_path(@conference.short_title, sponsor.id), method: :patch, class: 'btn btn-mini btn-warning' #to_contact.tab-pane - - if @conference.sponsors.to_contact.any? + - if @conference.sponsors.any? .row .col-md-12 %table.table.table-hover#sponsors @@ -175,33 +176,34 @@ %th Level %th Actions %tbody - - @conference.sponsors.to_contact.each do |sponsor| - %tr - %td - = image_tag(sponsor.picture.thumb.url, width: '20%') - %td - = link_to sponsor.name, admin_conference_sponsor_path(@conference.short_title, sponsor) - %td - = truncate(sponsor.description) - %td - = link_to sponsor.website_url, sponsor.website_url - %td - = sponsor.sponsorship_level.title - %td - .btn-group - = link_to 'Edit', edit_admin_conference_sponsor_path(@conference.short_title, sponsor), - method: :get, class: 'btn btn-mini btn-primary' - = link_to 'Delete', admin_conference_sponsor_path(@conference.short_title, sponsor), - method: :delete, class: 'btn btn-mini btn-danger', data: { confirm: "Do you really want to delete the sponsor #{sponsor.name}?" } - - if sponsor.transition_possible? :confirm - = link_to 'Confirm', confirm_admin_conference_sponsor_path(@conference.short_title, sponsor.id), - method: :patch, class: 'btn btn-mini btn-success' - - if sponsor.transition_possible? :contact - = link_to 'Contacted', contact_admin_conference_sponsor_path(@conference.short_title, sponsor.id), - method: :patch, class: 'btn btn-mini btn-default' - - if sponsor.transition_possible? :cancel - = link_to 'Cancel', cancel_admin_conference_sponsor_path(@conference.short_title, sponsor.id), - method: :patch, class: 'btn btn-mini btn-warning' + - @conference.sponsors.each do |sponsor| + - if sponsor.state =='to_contact' + %tr + %td + = image_tag(sponsor.picture.thumb.url, width: '20%') + %td + = link_to sponsor.name, admin_conference_sponsor_path(@conference.short_title, sponsor) + %td + = truncate(sponsor.description) + %td + = link_to sponsor.website_url, sponsor.website_url + %td + = sponsor.sponsorship_level.title + %td + .btn-group + = link_to 'Edit', edit_admin_conference_sponsor_path(@conference.short_title, sponsor), + method: :get, class: 'btn btn-mini btn-primary' + = link_to 'Delete', admin_conference_sponsor_path(@conference.short_title, sponsor), + method: :delete, class: 'btn btn-mini btn-danger', data: { confirm: "Do you really want to delete the sponsor #{sponsor.name}?" } + - if sponsor.transition_possible? :confirm + = link_to 'Confirm', confirm_admin_conference_sponsor_path(@conference.short_title, sponsor.id), + method: :patch, class: 'btn btn-mini btn-success' + - if sponsor.transition_possible? :contact + = link_to 'Mark as Contacted', contact_admin_conference_sponsor_path(@conference.short_title, sponsor.id), + method: :patch, class: 'btn btn-mini btn-default' + - if sponsor.transition_possible? :cancel + = link_to 'Cancel', cancel_admin_conference_sponsor_path(@conference.short_title, sponsor.id), + method: :patch, class: 'btn btn-mini btn-warning' - else %p There are no unconfirmed sponsors diff --git a/app/views/admin/sponsors/show.html.haml b/app/views/admin/sponsors/show.html.haml index 7186ab4e..169c23b2 100644 --- a/app/views/admin/sponsors/show.html.haml +++ b/app/views/admin/sponsors/show.html.haml @@ -74,7 +74,7 @@ off_text: 'No' } - - if @sponsor.has_swag + - if @sponsor.swag.length > 0 %tr %td.col-md-2 %b Swag's Type