Class: Koi::Tables::Cells::LinkComponent

Inherits:
Katalyst::Tables::CellComponent
  • Object
show all
Defined in:
app/components/koi/tables/cells/link_component.rb

Overview

Displays a link to the record The link text is the value of the attribute

Instance Method Summary collapse

Constructor Details

#initialize(url:, link:) ⇒ LinkComponent

Returns a new instance of LinkComponent.



11
12
13
14
15
16
17
# File 'app/components/koi/tables/cells/link_component.rb', line 11

def initialize(url:, link:, **)
  super(**)

  @url = url

  self.link_attributes = link
end

Instance Method Details

#rendered_valueObject



19
20
21
# File 'app/components/koi/tables/cells/link_component.rb', line 19

def rendered_value
  link_to(value, url, **link_attributes)
end

#urlObject



23
24
25
26
27
28
29
30
31
32
33
# File 'app/components/koi/tables/cells/link_component.rb', line 23

def url
  case @url
  when Symbol
    # helpers are not available until the component is rendered
    @url = helpers.public_send(@url, record)
  when Proc
    @url = @url.call(record)
  else
    @url
  end
end