From 3bf2ef05a3cd4c4fd4e5dc2e51a555f44ffacd0d Mon Sep 17 00:00:00 2001 From: Viacheslav Kharchenko Date: Mon, 3 Feb 2025 14:41:30 +0200 Subject: [PATCH 1/2] Redirect after update message and path --- lib/auxiliary_rails/concerns/resourceable.rb | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/auxiliary_rails/concerns/resourceable.rb b/lib/auxiliary_rails/concerns/resourceable.rb index 01a6e65..096a502 100644 --- a/lib/auxiliary_rails/concerns/resourceable.rb +++ b/lib/auxiliary_rails/concerns/resourceable.rb @@ -199,13 +199,19 @@ def redirect_after_create end def redirect_after_update - if flash[:notice].blank? - flash[:notice] = t('update.notice', - resource_name: resource_class.model_name.human, - scope: i18n_scope) - end + flash[:notice] ||= redirect_after_update_message - redirect_to resource_path(resource) + redirect_to redirect_after_update_path + end + + def redirect_after_update_message + t('update.notice', + resource_name: resource_class.model_name.human, + scope: i18n_scope) + end + + def redirect_after_update_path + resource_path(resource) end def redirect_after_destroy From 3ebf4a6ab5ba0e47cfcd6c25fff8afdc7440f0f5 Mon Sep 17 00:00:00 2001 From: Viacheslav Kharchenko Date: Mon, 10 Feb 2025 13:34:11 +0200 Subject: [PATCH 2/2] Redirect after create and destroy messages and paths --- lib/auxiliary_rails/concerns/resourceable.rb | 36 +++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/lib/auxiliary_rails/concerns/resourceable.rb b/lib/auxiliary_rails/concerns/resourceable.rb index 096a502..3229798 100644 --- a/lib/auxiliary_rails/concerns/resourceable.rb +++ b/lib/auxiliary_rails/concerns/resourceable.rb @@ -189,13 +189,19 @@ def new_resource_path # redirects def redirect_after_create - if flash[:notice].blank? - flash[:notice] = t('create.notice', - resource_name: resource_class.model_name.human, - scope: i18n_scope) - end + flash[:notice] ||= redirect_after_create_message + + redirect_to redirect_after_create_path + end + + def redirect_after_create_message + t('create.notice', + resource_name: resource_class.model_name.human, + scope: i18n_scope) + end - redirect_to resource_path(resource) + def redirect_after_create_path + resource_path(resource) end def redirect_after_update @@ -215,13 +221,19 @@ def redirect_after_update_path end def redirect_after_destroy - if flash[:notice].blank? - flash[:notice] = t('destroy.notice', - resource_name: resource_class.model_name.human, - scope: i18n_scope) - end + flash[:notice] ||= redirect_after_destroy_message + + redirect_to redirect_after_destroy_path + end + + def redirect_after_destroy_message + t('destroy.notice', + resource_name: resource_class.model_name.human, + scope: i18n_scope) + end - redirect_to collection_path + def redirect_after_destroy_path + collection_path end # system