From abf917ae37488a1acd509a4dda1b585b163e9c32 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Sun, 5 Nov 2023 13:02:34 +0100 Subject: [PATCH] Switch to Hash syntax for URL generation in breadcrumbs This will prevent an exception if the corresponding Route cannot be generated. --- .../application/_breadcrumbs_and_title.html.slim | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/views/application/_breadcrumbs_and_title.html.slim b/app/views/application/_breadcrumbs_and_title.html.slim index 91be5cca..a8ef006a 100644 --- a/app/views/application/_breadcrumbs_and_title.html.slim +++ b/app/views/application/_breadcrumbs_and_title.html.slim @@ -5,19 +5,19 @@ - parent_route_key = parent_model.model_name.singular_route_key - if params["#{parent_route_key}_id"].present? - parent_object = object.try(parent_route_key) || parent_model.find_by(id: params["#{parent_route_key}_id"]) - - parent_element = link_to_if(current_user && policy(parent_object).show?, parent_object, send(:"#{parent_route_key}_path", parent_object)) - - parent_root_element = link_to_if(current_user && policy(parent_model).index?, parent_model.model_name.human(count: 2), send(:"#{parent_model.model_name.collection}_path")) - - root_element = link_to_if(current_user && policy(model).index?, model.model_name.human(count: 2), send(:"#{parent_route_key}_#{model.model_name.collection}_path", parent_object)) + - parent_element = link_to_if(current_user && policy(parent_object).show?, parent_object, {controller: parent_model.model_name.route_key, action: :show, id: parent_object.id}) + - parent_root_element = link_to_if(current_user && policy(parent_model).index?, parent_model.model_name.human(count: 2), {controller: parent_model.model_name.route_key, action: :index}) + - root_element = link_to_if(current_user && policy(model).index?, model.model_name.human(count: 2), send(:"#{parent_route_key}_#{model.model_name.route_key}_path", parent_object)) - if object - current_element = link_to_if(current_user && policy(object).show?, object, send(:"#{parent_route_key}_#{model.model_name.singular}_path", parent_object, object)) - else - - root_element = link_to_if(current_user && policy(model).index?, model.model_name.human(count: 2), send(:"#{model.model_name.collection}_path")) + - root_element = link_to_if(current_user && policy(model).index?, model.model_name.human(count: 2), {controller: model.model_name.route_key, action: :index}) - if object - - current_element = link_to_if(current_user && policy(object).show?, object, send(:"#{model.model_name.singular}_path", object)) + - current_element = link_to_if(current_user && policy(object).show?, object, {controller: model.model_name.route_key, action: :show, id: object.id}) - else - - root_element = link_to_if(current_user && policy(model).index?, model.model_name.human(count: 2), send(:"#{model.model_name.collection}_path")) + - root_element = link_to_if(current_user && policy(model).index?, model.model_name.human(count: 2), {controller: model.model_name.route_key, action: :index}) - if object - - current_element = link_to_if(current_user && policy(object).show?, object, send(:"#{model.model_name.singular}_path", object)) + - current_element = link_to_if(current_user && policy(object).show?, object, {controller: model.model_name.route_key, action: :show, id: object.id}) - if I18n.exists?("shared.#{params[:action]}") - active_action = t("shared.#{params[:action]}", model: model&.model_name&.human) - else