From 5fa6ba40d90df9c1711d1b5eeff34686dda133a2 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Wed, 6 Apr 2022 13:30:53 +0100 Subject: [PATCH] Make resend_code route configurable --- lib/two_factor_authentication/routes.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/two_factor_authentication/routes.rb b/lib/two_factor_authentication/routes.rb index 543059a..f198038 100644 --- a/lib/two_factor_authentication/routes.rb +++ b/lib/two_factor_authentication/routes.rb @@ -4,8 +4,16 @@ module ActionDispatch::Routing def devise_two_factor_authentication(mapping, controllers) resource :two_factor_authentication, :only => [:show, :update, :resend_code], :path => mapping.path_names[:two_factor_authentication], :controller => controllers[:two_factor_authentication] do - collection { get "resend_code" } + collection { get resend_code_path(mapping), as: "resend_code" } end end + + def resend_code_path(mapping) + Devise.mappings[resource_name(mapping)].path_names[:two_factor_authentication_resend_code] || "resend_code" + end + + def resource_name(mapping) + mapping.class_name.underscore.to_sym + end end end