From 7be3cf781950d768a71a4e412aabd5aa6b8809e9 Mon Sep 17 00:00:00 2001 From: Pavel Kalashnikov Date: Fri, 13 Sep 2024 18:57:01 +0400 Subject: [PATCH] Issue #81. Upgrade helper method --- lib/tramway/configs/entity.rb | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/tramway/configs/entity.rb b/lib/tramway/configs/entity.rb index eb3f5406..113e307b 100644 --- a/lib/tramway/configs/entity.rb +++ b/lib/tramway/configs/entity.rb @@ -17,7 +17,7 @@ class Entity < Dry::Struct HumanNameStruct = Struct.new(:single, :plural) def routes - RouteStruct.new(Rails.application.routes.url_helpers.public_send(route_helper_method)) + RouteStruct.new(route_helper_method) end def human_name @@ -34,7 +34,7 @@ def human_name private def model_class - name.camelize.constantize + name.classify.constantize rescue StandardError nil end @@ -42,11 +42,17 @@ def model_class def route_helper_method underscored_name = name.parameterize.pluralize.underscore - if route.present? - route.helper_method_by(underscored_name) - else - "#{underscored_name}_path" - end + engine, method_name = if pages.include?(:index) + [Tramway::Engine, "#{underscored_name}_path"] + else + if route.present? + [Rails.application, route.helper_method_by(underscored_name)] + else + [Rails.application, "#{underscored_name}_path"] + end + end + + engine.routes.url_helpers.public_send(method_name) end end end