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

@@ -35,11 +35,7 @@ class ArtistsController < ApplicationController
@artists = @artists.includes(:tag) if request.format.html?
@artists = @artists.includes(:urls) if !request.format.html?
if params[:redirect].to_s.truthy? && @artists.one? && @artists.first.name == Artist.normalize_name(params[:search][:any_name_or_url_matches])
redirect_to @artists.first
else
respond_with @artists
end
respond_with(@artists)
end
def show
@@ -85,6 +81,14 @@ class ArtistsController < ApplicationController
private
def item_matches_params(artist)
if params[:search][:any_name_or_url_matches]
artist.name == Artist.normalize_name(params[:search][:any_name_or_url_matches])
else
true
end
end
def load_artist
@artist = Artist.find(params[:id])
end