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 <body> tag, but this failed
because evaluating the `current_item` raised an exception again.
This commit is contained in:
evazion
2022-03-01 17:09:31 -06:00
parent 99221af855
commit ece0b1b17d
2 changed files with 15 additions and 6 deletions

View File

@@ -264,9 +264,18 @@ module ApplicationHelper
render "table_builder/table", table: table render "table_builder/table", table: table
end end
def body_attributes(current_user, params, current_item = nil) def body_attributes(current_user, params, current_item, exception)
controller_param = params[:controller].parameterize.dasherize if exception
action_param = params[:action].parameterize.dasherize 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", lang: "en",
@@ -275,12 +284,12 @@ module ApplicationHelper
data: { data: {
controller: controller_param, controller: controller_param,
action: action_param, action: action_param,
layout: controller.class.send(:_layout), layout: layout,
"current-user-ip-addr": request.remote_ip, "current-user-ip-addr": request.remote_ip,
"current-user-save-data": CurrentUser.save_data, "current-user-save-data": CurrentUser.save_data,
**current_user_data_attributes(current_user), **current_user_data_attributes(current_user),
**cookie_data_attributes, **cookie_data_attributes,
**current_item_data_attributes(current_item), **extra_attributes,
} }
} }
end end

View File

@@ -57,7 +57,7 @@
<%= yield :html_header %> <%= yield :html_header %>
<%= raw Danbooru.config.custom_html_header_content %> <%= raw Danbooru.config.custom_html_header_content %>
</head> </head>
<%= 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" %> <%= render "news_updates/listing" %>
<header id="top" class="mb-4"> <header id="top" class="mb-4">