Class: ApplicationComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- ApplicationComponent
- Defined in:
- app/components/application_component.rb
Overview
Base component class for all ViewComponents
Provides convenient access to common helpers without needing the helpers. prefix.
== Block-Capturing Helpers Warning
IMPORTANT: Do NOT delegate helpers that accept blocks (link_to, content_tag, tag, form_with, etc.)
When you delegate a block-accepting helper, it routes through the helpers proxy which breaks
ViewComponent's block capture mechanism. This causes symptoms like:
- Block content rendering BEFORE the wrapper element
- Raw HTML tags (, ) appearing as visible text
- Escaped HTML inside elements
== Solution for Components Using Block Helpers
Components that need link_to, content_tag, tag, or other block-accepting helpers
must include the ActionView helper modules directly:
class MyComponent < ApplicationComponent
include ActionView::Helpers::TagHelper
include ActionView::Helpers::UrlHelper
# ... now link_to with blocks works correctly
end
== References
- ViewComponent docs: https://viewcomponent.org/guide/helpers.html
- Best practices: https://tips.rstankov.com/p/tips-for-using-viewcomponents-in
- Project docs: doc/features/VIEW_COMPONENTS.MD
Direct Known Subclasses
Crm::ActivityCardComponent, Crm::ContactCardComponent, Crm::ContentLinkEditorComponent, Crm::DailyFocusSummaryComponent, Crm::DailyFocusWidgetComponent, Crm::OppFunnelWidgetComponent, Crm::PostSeoPanelComponent, Crm::QuickSearchResultCardComponent, Crm::RevenueWidgetComponent, Crm::SeoDashboardComponent, Crm::StickyHeaderComponent, Crm::StickyHeaderComponent::NavItem, PartyAvatarComponent, SocialShareComponent, Www::AddToCartButtonComponent, Www::AssociationsSliderComponent, Www::BenefitsListComponent, Www::BlogFaqItemComponent, Www::BlogFaqSectionComponent, Www::BlogPostCardComponent, Www::BlogProductEmbedComponent, Www::CardGridComponent, Www::CarouselSliderComponent, Www::DesktopMenuComponent, Www::DocumentCardComponent, Www::FaqItemComponent, Www::FaqListComponent, Www::FeatureListComponent, Www::FloorCompatibilityTableComponent, Www::FloorHeatingCalculatorComponent, Www::FloorplanCategoryComponent, Www::FullWidthLandingPageHeaderComponent, Www::HomepageProductsComponent, Www::LandingPageCompareComponent, Www::LandingPageCtaLinkComponent, Www::LeadFormModalComponent, Www::MagazineBlogCardComponent, Www::MobileMenuComponent, Www::NavbarMenuComponent, Www::ProductCardComponent, Www::ProductCardsComponent, Www::ProductCategoryCardsComponent, Www::ProductCompareTableComponent, Www::ProductShowcaseComponent, Www::PublicationCardComponent, Www::RadiantPanelFiltersComponent, Www::RequestSmartplanSectionComponent, Www::ReviewsIo::ProductRatingComponent, Www::ReviewsIo::RatingBarComponent, Www::ReviewsIo::ReviewListComponent, Www::ReviewsIo::ReviewSliderComponent, Www::SaleBadgeComponent, Www::SectionHeaderComponent, Www::SectionNavComponent, Www::ShowcaseGridComponent, Www::SnowMeltingCalculatorComponent, Www::SnowMeltingQuoteFormComponent, Www::SupportPageHeaderComponent, Www::SupportPublicationsComponent, Www::SupportSpecificationsComponent, Www::TowelWarmerConnectionOptionsComponent, Www::TowelWarmerFiltersComponent, Www::TrainingCardComponent, Www::VideoSectionComponent
Delegated Instance Attributes collapse
-
#cms_link ⇒ Object
Alias for Helpers#cms_link.
-
#image_asset_tag ⇒ Object
Alias for Helpers#image_asset_tag.
-
#image_tag ⇒ Object
Alias for Helpers#image_tag.
-
#number_to_currency ⇒ Object
Alias for Helpers#number_to_currency.
-
#number_with_delimiter ⇒ Object
Alias for Helpers#number_with_delimiter.
-
#post_path ⇒ Object
Alias for Helpers#post_path.
-
#post_url ⇒ Object
Alias for Helpers#post_url.
-
#strip_tags ⇒ Object
Alias for Helpers#strip_tags.
Instance Method Summary collapse
-
#fetch_or_fallback(argument, constant, fallback) ⇒ Object
protected
Utility method for validating arguments against allowed values with fallback Ported from Railsboot::Component for compatibility.
Instance Method Details
#cms_link ⇒ Object
Alias for Helpers#cms_link
39 40 41 42 |
# File 'app/components/application_component.rb', line 39 delegate :image_tag, :image_asset_tag, :number_to_currency, :number_with_delimiter, :cms_link, :post_url, :post_path, :strip_tags, to: :helpers |
#fetch_or_fallback(argument, constant, fallback) ⇒ Object (protected)
Utility method for validating arguments against allowed values with fallback
Ported from Railsboot::Component for compatibility
48 49 50 51 52 53 54 |
# File 'app/components/application_component.rb', line 48 def fetch_or_fallback(argument, constant, fallback) if argument.present? && constant.include?(argument.to_s) argument else fallback end end |
#image_asset_tag ⇒ Object
Alias for Helpers#image_asset_tag
39 40 41 42 |
# File 'app/components/application_component.rb', line 39 delegate :image_tag, :image_asset_tag, :number_to_currency, :number_with_delimiter, :cms_link, :post_url, :post_path, :strip_tags, to: :helpers |
#image_tag ⇒ Object
Alias for Helpers#image_tag
39 40 41 42 |
# File 'app/components/application_component.rb', line 39 delegate :image_tag, :image_asset_tag, :number_to_currency, :number_with_delimiter, :cms_link, :post_url, :post_path, :strip_tags, to: :helpers |
#number_to_currency ⇒ Object
Alias for Helpers#number_to_currency
39 40 41 42 |
# File 'app/components/application_component.rb', line 39 delegate :image_tag, :image_asset_tag, :number_to_currency, :number_with_delimiter, :cms_link, :post_url, :post_path, :strip_tags, to: :helpers |
#number_with_delimiter ⇒ Object
Alias for Helpers#number_with_delimiter
39 40 41 42 |
# File 'app/components/application_component.rb', line 39 delegate :image_tag, :image_asset_tag, :number_to_currency, :number_with_delimiter, :cms_link, :post_url, :post_path, :strip_tags, to: :helpers |
#post_path ⇒ Object
Alias for Helpers#post_path
39 40 41 42 |
# File 'app/components/application_component.rb', line 39 delegate :image_tag, :image_asset_tag, :number_to_currency, :number_with_delimiter, :cms_link, :post_url, :post_path, :strip_tags, to: :helpers |
#post_url ⇒ Object
Alias for Helpers#post_url
39 40 41 42 |
# File 'app/components/application_component.rb', line 39 delegate :image_tag, :image_asset_tag, :number_to_currency, :number_with_delimiter, :cms_link, :post_url, :post_path, :strip_tags, to: :helpers |
#strip_tags ⇒ Object
Alias for Helpers#strip_tags
39 40 41 42 |
# File 'app/components/application_component.rb', line 39 delegate :image_tag, :image_asset_tag, :number_to_currency, :number_with_delimiter, :cms_link, :post_url, :post_path, :strip_tags, to: :helpers |