Skip to content

Commit

Permalink
Do not call routing helpers before render
Browse files Browse the repository at this point in the history
Rails' `mounted_helpers` do not work when a component is initialized.
They need to be called when the component is rendered. This change moves
the rendering of tabs from initialization time to render time.
  • Loading branch information
mamhoff committed Jan 3, 2025
1 parent c26a91a commit 2013817
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<%= page do %>
<% if @tabs %>
<% if tabs %>
<%= page_header do %>
<%= render_title %>
<% end %>

<%= page_header do %>
<% rendered_tabs = capture do %>
<% @tabs.each do %>
<% renderable_tabs.each do %>
<%= render(component("ui/button").new(tag: :a, scheme: :ghost, text: _1.text, 'aria-current': _1.current, href: _1.href)) %>
<% end %>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@ def columns; []; end

def initialize(page:)
@page = page
@tabs = tabs&.map { |tab| Tab.new(**tab) }
end

def row_fade(_record)
false
end

def renderable_tabs
return unless tabs

tabs.map { |tab| Tab.new(**tab) }
end

def title
model_class.model_name.human.pluralize
end
Expand Down

0 comments on commit 2013817

Please sign in to comment.