Class: Koi::Header::ShowComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Koi::Header::ShowComponent
- Defined in:
- app/components/koi/header/show_component.rb
Instance Attribute Summary collapse
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
- #add_edit(header) ⇒ Object
- #add_index(header) ⇒ Object
- #call ⇒ Object
-
#initialize(resource:, title: nil) ⇒ ShowComponent
constructor
A new instance of ShowComponent.
- #title ⇒ Object
Constructor Details
#initialize(resource:, title: nil) ⇒ ShowComponent
Returns a new instance of ShowComponent.
10 11 12 13 14 15 16 17 |
# File 'app/components/koi/header/show_component.rb', line 10 def initialize(resource:, title: nil) super @title = title @resource = resource @header = HeaderComponent.new(title: self.title) end |
Instance Attribute Details
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
6 7 8 |
# File 'app/components/koi/header/show_component.rb', line 6 def resource @resource end |
Instance Method Details
#add_edit(header) ⇒ Object
44 45 46 47 48 |
# File 'app/components/koi/header/show_component.rb', line 44 def add_edit(header) header.with_action("Edit", url_for(action: :edit)) rescue ActionController::UrlGenerationError nil end |
#add_index(header) ⇒ Object
38 39 40 41 42 |
# File 'app/components/koi/header/show_component.rb', line 38 def add_index(header) header.(resource.model_name.human.pluralize, url_for(action: :index)) rescue ActionController::UrlGenerationError nil end |
#call ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'app/components/koi/header/show_component.rb', line 19 def call render @header do |header| # render block, if any (delegating slots to header) content # add our breadcrumbs and actions add_index(header) add_edit(header) end end |