Added universal redirect on the index action

- Only controllers with show actions will redirect on the index action
- Parameter checking is individualized per controller for the redirect check
This commit is contained in:
BrokenEagle
2020-01-25 20:28:08 +00:00
parent c1f2cd8d9d
commit 75ac11166c
5 changed files with 58 additions and 20 deletions

View File

@@ -17,11 +17,7 @@ class WikiPagesController < ApplicationController
def index
@wiki_pages = WikiPage.paginated_search(params)
if params[:redirect].to_s.truthy? && @wiki_pages.one? && @wiki_pages.first.title == WikiPage.normalize_title(params[:search][:title])
redirect_to @wiki_pages.first
else
respond_with(@wiki_pages)
end
respond_with(@wiki_pages)
end
def search
@@ -80,6 +76,14 @@ class WikiPagesController < ApplicationController
private
def item_matches_params(wiki_page)
if params[:search][:title]
wiki_page.title == WikiPage.normalize_title(params[:search][:title])
else
true
end
end
def normalize_search_params
if params[:title]
params[:search] ||= {}