From 77a59b0037ff25511de03a2b070310309f2f7b9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasia=20Jarmo=C5=82kowicz?= Date: Thu, 5 Jul 2018 16:11:08 +0200 Subject: [PATCH] Fix peer-to-peer action --- app/controllers/campaigns_controller.rb | 18 ++++++++++++------ app/views/campaigns/peer_to_peer.html.erb | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/controllers/campaigns_controller.rb b/app/controllers/campaigns_controller.rb index 9a861bbe..24256c7c 100644 --- a/app/controllers/campaigns_controller.rb +++ b/app/controllers/campaigns_controller.rb @@ -110,16 +110,22 @@ class CampaignsController < ApplicationController session[:donor_signup_url] = request.env["REQUEST_URI"] @nonprofit = Nonprofit.find_by_id(params[:npo_id]) @parent_campaign = Campaign.find_by_id(params[:campaign_id]) - @child_campaign = Campaign.where( - profile_id: current_user.profile.id, - parent_campaign_id: @parent_campaign.id - ).first if @parent_campaign - @profile = current_user.profile if current_user + + if params[:campaign_id].present? && !@parent_campaign + raise ActionController::RoutingError.new('Not Found') + end + + if current_user + @profile = current_user.profile + @child_campaign = Campaign.where( + profile_id: @profile.id, + parent_campaign_id: @parent_campaign.id + ).first + end end private - # TODO: test if this can be passed by p2p campaign editor def check_nonprofit_status if !current_role?(:super_admin) && !current_nonprofit.published raise ActionController::RoutingError.new('Not Found') diff --git a/app/views/campaigns/peer_to_peer.html.erb b/app/views/campaigns/peer_to_peer.html.erb index e4bdbcf2..40072e98 100644 --- a/app/views/campaigns/peer_to_peer.html.erb +++ b/app/views/campaigns/peer_to_peer.html.erb @@ -38,7 +38,7 @@ <%= IncludeAsset.js '/client/js/campaigns/peer_to_peer/page.js' %> <% end %> -<% if @parent_campaign.banner_image_url %> +<% if @parent_campaign && @parent_campaign.banner_image_url %>