diff --git a/app/controllers/campaigns_controller.rb b/app/controllers/campaigns_controller.rb index f5a0aace..861370a7 100644 --- a/app/controllers/campaigns_controller.rb +++ b/app/controllers/campaigns_controller.rb @@ -9,14 +9,19 @@ class CampaignsController < ApplicationController def index @nonprofit = current_nonprofit - @campaigns = @nonprofit.campaigns.includes(:nonprofit).not_deleted.order('created_at desc') + if (current_nonprofit_user?) + @campaigns = @nonprofit.campaigns.includes(:nonprofit).not_deleted.order('created_at desc') + @deleted_campaigns = @nonprofit.campaigns.includes(:nonprofit).deleted.order('created_at desc') + else + @campaigns = @nonprofit.campaigns.includes(:nonprofit).not_deleted.not_a_child.order('created_at desc') + @deleted_campaigns = @nonprofit.campaigns.includes(:nonprofit).deleted.not_a_child.order('created_at desc') + end respond_to do |format| format.html do @active_campaigns = @campaigns.active @past_campaigns = @campaigns.past @unpublished_campaigns = @campaigns.unpublished - @deleted_campaigns = @nonprofit.campaigns.deleted.order('created_at desc') end format.json do diff --git a/app/controllers/nonprofits_controller.rb b/app/controllers/nonprofits_controller.rb index 9a78baf9..d33e46a4 100755 --- a/app/controllers/nonprofits_controller.rb +++ b/app/controllers/nonprofits_controller.rb @@ -19,7 +19,7 @@ @profiles = @nonprofit.profiles.order('total_raised DESC').limit(5).includes(:user).uniq events = @nonprofit.events.not_deleted.order('start_datetime desc') - campaigns = @nonprofit.campaigns.not_deleted.order('created_at desc') + campaigns = @nonprofit.campaigns.not_deleted.not_a_child.order('created_at desc') @events = events.upcoming @any_past_events = events.past.any? diff --git a/app/models/campaign.rb b/app/models/campaign.rb index c4c64669..f0d62fcc 100644 --- a/app/models/campaign.rb +++ b/app/models/campaign.rb @@ -76,6 +76,7 @@ class Campaign < ActiveRecord::Base scope :unpublished, -> {where(:published => [nil, false])} scope :not_deleted, -> {where(deleted: [nil, false])} scope :deleted, -> {where(deleted: true)} + scope :not_a_child, -> {where(parent_campaign_id: nil)} before_validation do if self.goal_amount_dollars.present?