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.
25 lines
627 B
Ruby
25 lines
627 B
Ruby
class Shared::BannerComponent < ApplicationComponent
|
|
attr_reader :banner_or_section
|
|
|
|
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
|
|
|
|
def link
|
|
link_to banner.target_url do
|
|
tag.h2(banner.title, style: "color:#{banner.font_color}") +
|
|
tag.h3(banner.description, style: "color:#{banner.font_color}")
|
|
end
|
|
end
|
|
end
|