From c73de731d2e98d530fa37e47f3059bcc8a7b9807 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Fri, 20 Dec 2024 22:24:01 +0100 Subject: [PATCH] Do not call routing helpers before render 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. --- .../solidus_admin/ui/pages/index/component.html.erb | 4 ++-- .../components/solidus_admin/ui/pages/index/component.rb | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/admin/app/components/solidus_admin/ui/pages/index/component.html.erb b/admin/app/components/solidus_admin/ui/pages/index/component.html.erb index 69916f08dd4..caa79f05cc6 100644 --- a/admin/app/components/solidus_admin/ui/pages/index/component.html.erb +++ b/admin/app/components/solidus_admin/ui/pages/index/component.html.erb @@ -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 %> diff --git a/admin/app/components/solidus_admin/ui/pages/index/component.rb b/admin/app/components/solidus_admin/ui/pages/index/component.rb index ad6cd5b5092..b81be0cb240 100644 --- a/admin/app/components/solidus_admin/ui/pages/index/component.rb +++ b/admin/app/components/solidus_admin/ui/pages/index/component.rb @@ -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