From 117a85a4658c562d8be76d2ce6942a1e6a3b3d4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janko=20Marohni=C4=87?= Date: Mon, 20 Nov 2023 22:48:32 +0100 Subject: [PATCH] Support older Rails versions --- lib/rodauth/rails/feature/base.rb | 4 ++-- lib/rodauth/rails/routing.rb | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/rodauth/rails/feature/base.rb b/lib/rodauth/rails/feature/base.rb index a8bcba5..22dbdec 100644 --- a/lib/rodauth/rails/feature/base.rb +++ b/lib/rodauth/rails/feature/base.rb @@ -63,9 +63,9 @@ def before_rodauth end def rails_path_parameters - controller = [rails_controller.module_parent_name&.underscore, rails_controller.controller_name].compact.join("/") + controller = rails_controller.name.delete_suffix("Controller").underscore route_method = self.class.route_hash.fetch(request.path.sub(/^#{prefix}/, "")) - action = route_method.to_s.sub(/^handle_/, "") + action = route_method.to_s.delete_prefix("handle_") { controller: controller, action: action } end diff --git a/lib/rodauth/rails/routing.rb b/lib/rodauth/rails/routing.rb index 2449522..9d9966a 100644 --- a/lib/rodauth/rails/routing.rb +++ b/lib/rodauth/rails/routing.rb @@ -5,16 +5,14 @@ def rodauth(name = nil, as: name) auth_class = Rodauth::Rails.app.rodauth!(name) scope = auth_class.roda_class.new({}) rodauth = auth_class.new(scope) + controller = rodauth.rails_controller.name.delete_suffix("Controller").underscore - controller = rodauth.rails_controller.controller_name - namespace = rodauth.rails_controller.module_parent_name&.underscore - - scope controller: controller, module: namespace, as: as, format: false do + scope controller: controller, as: as, format: false do auth_class.route_hash.each do |route_path, route_method| next if route_method.to_s.end_with?("_js") path = "#{rodauth.prefix}/#{route_path}" - action = route_method.to_s.sub(/\Ahandle_/, "") + action = route_method.to_s.delete_prefix("handle_") verbs = rodauth_verbs(rodauth, route_method) match path, action: action, as: action, via: verbs