Class: Koi::Header::NewComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Koi::Header::NewComponent
- Defined in:
- app/components/koi/header/new_component.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #add_index(header) ⇒ Object
- #call ⇒ Object
-
#initialize(model:, title: nil) ⇒ NewComponent
constructor
A new instance of NewComponent.
- #title ⇒ Object
Constructor Details
#initialize(model:, title: nil) ⇒ NewComponent
Returns a new instance of NewComponent.
10 11 12 13 14 15 16 17 |
# File 'app/components/koi/header/new_component.rb', line 10 def initialize(model:, title: nil) super @model = model @title = title @header = HeaderComponent.new(title: self.title) end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
6 7 8 |
# File 'app/components/koi/header/new_component.rb', line 6 def model @model end |
Instance Method Details
#add_index(header) ⇒ Object
33 34 35 36 37 |
# File 'app/components/koi/header/new_component.rb', line 33 def add_index(header) header.(model.model_name.human.pluralize, url_for(action: :index)) rescue ActionController::UrlGenerationError nil end |
#call ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'app/components/koi/header/new_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) end end |
#title ⇒ Object
29 30 31 |
# File 'app/components/koi/header/new_component.rb', line 29 def title @title || "New #{model.model_name.human.downcase}" end |