From ece0b1b17d316967516a234b3b572a11f17aae19 Mon Sep 17 00:00:00 2001 From: evazion Date: Tue, 1 Mar 2022 17:09:31 -0600 Subject: [PATCH] Fix exception on error page when handling PG::AmbiguousColumn error. Fix an exception on the error page when a controller index action raised an PG::AmbiguousColumn error because the model `search` method generated SQL with an ambiguous column reference. In this case the error page tried to generate data attributes for the tag, but this failed because evaluating the `current_item` raised an exception again. --- app/helpers/application_helper.rb | 19 ++++++++++++++----- app/views/layouts/default.html.erb | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 509aa83e2..5407404fd 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -264,9 +264,18 @@ module ApplicationHelper render "table_builder/table", table: table end - def body_attributes(current_user, params, current_item = nil) - controller_param = params[:controller].parameterize.dasherize - action_param = params[:action].parameterize.dasherize + def body_attributes(current_user, params, current_item, exception) + if exception + controller_param = "static" + action_param = "error" + layout = nil + extra_attributes = {} + else + controller_param = params[:controller].parameterize.dasherize + action_param = params[:action].parameterize.dasherize + layout = controller.class.send(:_layout) + extra_attributes = current_item_data_attributes(current_item) + end { lang: "en", @@ -275,12 +284,12 @@ module ApplicationHelper data: { controller: controller_param, action: action_param, - layout: controller.class.send(:_layout), + layout: layout, "current-user-ip-addr": request.remote_ip, "current-user-save-data": CurrentUser.save_data, **current_user_data_attributes(current_user), **cookie_data_attributes, - **current_item_data_attributes(current_item), + **extra_attributes, } } end diff --git a/app/views/layouts/default.html.erb b/app/views/layouts/default.html.erb index d09cc2193..6b9e08b43 100644 --- a/app/views/layouts/default.html.erb +++ b/app/views/layouts/default.html.erb @@ -57,7 +57,7 @@ <%= yield :html_header %> <%= raw Danbooru.config.custom_html_header_content %> -<%= tag.body **body_attributes(CurrentUser.user, params, @current_item) do %> +<%= tag.body **body_attributes(CurrentUser.user, params, @current_item, @exception) do %> <%= render "news_updates/listing" %>