diff --git a/app/components/shared/banner_component.rb b/app/components/shared/banner_component.rb index fcbb5a727..de61e1602 100644 --- a/app/components/shared/banner_component.rb +++ b/app/components/shared/banner_component.rb @@ -1,8 +1,16 @@ class Shared::BannerComponent < ApplicationComponent - attr_reader :banner + attr_reader :banner_or_section - def initialize(banner) - @banner = banner + def initialize(banner_or_section) + @banner_or_section = banner_or_section + end + + def banner + @banner ||= if banner_or_section.respond_to?(:sections) + banner_or_section + else + Banner.in_section(banner_or_section).with_active.sample + end end private diff --git a/app/controllers/budgets_controller.rb b/app/controllers/budgets_controller.rb index 9fb0b0bf6..ec7e93f57 100644 --- a/app/controllers/budgets_controller.rb +++ b/app/controllers/budgets_controller.rb @@ -17,7 +17,6 @@ class BudgetsController < ApplicationController def index @finished_budgets = @budgets.finished.order(created_at: :desc) @budgets_coordinates = current_budget_map_locations - @banners = Banner.in_section("budgets").with_active end private diff --git a/app/controllers/concerns/commentable_actions.rb b/app/controllers/concerns/commentable_actions.rb index 8b2a6d3bc..5523285bf 100644 --- a/app/controllers/concerns/commentable_actions.rb +++ b/app/controllers/concerns/commentable_actions.rb @@ -16,7 +16,6 @@ module CommentableActions index_customization @tag_cloud = tag_cloud - @banners = Banner.in_section(section(resource_model.name)).with_active set_resource_votes(@resources) @@ -110,15 +109,6 @@ module CommentableActions nil end - def section(resource_name) - case resource_name - when "Proposal" - "proposals" - when "Debate" - "debates" - end - end - def featured_proposals @featured_proposals ||= [] end diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index a4b01cf09..03bb40828 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -6,7 +6,6 @@ class PagesController < ApplicationController def show @custom_page = SiteCustomization::Page.published.find_by(slug: params[:id]) - @banners = Banner.in_section("help_page").with_active if @custom_page.present? @cards = @custom_page.cards diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 4e3081e73..9fa9bf1f2 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -11,7 +11,6 @@ class WelcomeController < ApplicationController @header = Widget::Card.header.first @feeds = Widget::Feed.active @cards = Widget::Card.body - @banners = Banner.in_section("homepage").with_active @remote_translations = detect_remote_translations(@feeds, @recommended_debates, @recommended_proposals) diff --git a/app/views/admin/banners/_form.html.erb b/app/views/admin/banners/_form.html.erb index 70e55079e..8737b760b 100644 --- a/app/views/admin/banners/_form.html.erb +++ b/app/views/admin/banners/_form.html.erb @@ -79,6 +79,6 @@