controllers: fix index redirect param to not redirect to .html extension.

Fix searches like this:

* https://danbooru.donmai.u/wiki_pages?search[title]=touhou&redirect=true

To redirect to this:

* https://danbooru.donmai.u/wiki_pages/touhou

Instead of this:

* https://danbooru.donmai.u/wiki_pages/touhou.html

This also fixes redirects when searching for users on profile pages, and during pagination on media
asset show pages.
This commit is contained in:
evazion
2022-11-28 17:05:58 -06:00
parent 096efdee7b
commit 068d435f56

View File

@@ -75,8 +75,12 @@ class ApplicationController < ActionController::Base
end end
def redirect_to_show(items) def redirect_to_show(items)
if request.format.html?
redirect_to send("#{controller_path.singularize}_path", items.first)
else
redirect_to send("#{controller_path.singularize}_path", items.first, format: request.format.symbol) redirect_to send("#{controller_path.singularize}_path", items.first, format: request.format.symbol)
end end
end
def is_redirect?(items) def is_redirect?(items)
action_methods.include?("show") && params[:redirect].to_s.truthy? && items.one? && item_matches_params(items.first) action_methods.include?("show") && params[:redirect].to_s.truthy? && items.one? && item_matches_params(items.first)