From 6b94b10979e5a9542ff5d8a953afe45c8e427583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasia=20Jarmo=C5=82kowicz?= Date: Wed, 30 May 2018 22:25:16 +0200 Subject: [PATCH] Don't allow to create more than one child campaign per user --- app/controllers/campaigns_controller.rb | 4 ++ app/views/campaigns/peer_to_peer.html.erb | 49 +++++++++++++---------- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/app/controllers/campaigns_controller.rb b/app/controllers/campaigns_controller.rb index 033af077..6008dcaa 100644 --- a/app/controllers/campaigns_controller.rb +++ b/app/controllers/campaigns_controller.rb @@ -111,6 +111,10 @@ 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 end diff --git a/app/views/campaigns/peer_to_peer.html.erb b/app/views/campaigns/peer_to_peer.html.erb index beacbe40..e4bdbcf2 100644 --- a/app/views/campaigns/peer_to_peer.html.erb +++ b/app/views/campaigns/peer_to_peer.html.erb @@ -116,29 +116,36 @@
  • -

    Start your campaign

    - 5 minutes -
    -

    Use our simple wizard to create your campaign for - - - . - - - - your favorite nonprofit. - -

    -

    If you need any further help setting up your campaign, check out this handy article.

    -
    - + <% if !@child_campaign %> +

    Start your campaign

    + 5 minutes +
    +

    Use our simple wizard to create your campaign for + + + . + + + + your favorite nonprofit. + +

    +

    If you need any further help setting up your campaign, check out this handy article.

    +
    + +
    -
    + <% else %> +

    + Seems like you already have a campaign for that cause! <%= link_to "Click here to see it", @child_campaign.url %>. +

    + <% end %>
  • +