Simplify rendering a banner
Now the banner component accepts either a banner or a section and loads the banner if it's a section, so we don't have to add the `@banners` variable in several controllers.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user