diff --git a/app/controllers/artists_controller.rb b/app/controllers/artists_controller.rb index fdb683d6a..910a4bc17 100644 --- a/app/controllers/artists_controller.rb +++ b/app/controllers/artists_controller.rb @@ -37,14 +37,12 @@ class ArtistsController < ApplicationController end def index - @artists = Artist.includes(:urls).search(search_params).paginate(params[:page], :limit => params[:limit], :search_count => params[:search]) - respond_with(@artists) do |format| - format.xml do - render :xml => @artists.to_xml(:include => [:urls], :root => "artists") - end - format.json do - render :json => @artists.to_json(:include => [:urls]) - end + @artists = Artist.includes(:urls).paginated_search(params) + + 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 end diff --git a/app/controllers/pools_controller.rb b/app/controllers/pools_controller.rb index 3d35d2636..9fdbf748f 100644 --- a/app/controllers/pools_controller.rb +++ b/app/controllers/pools_controller.rb @@ -18,7 +18,12 @@ class PoolsController < ApplicationController def index @pools = Pool.includes(:creator).paginated_search(params, count_pages: true) - respond_with(@pools) + + if params[:redirect].to_s.truthy? && @pools.one? && Pool.normalize_name_for_search(@pools.first.name) == Pool.normalize_name_for_search(params[:search][:name_matches]) + redirect_to @pools.first + else + respond_with @pools + end end def gallery diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 864d1a520..3dd6432c4 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -28,9 +28,14 @@ class UsersController < ApplicationController if params[:name].present? @user = User.find_by_name!(params[:name]) redirect_to user_path(@user) + return + end + + @users = User.paginated_search(params) + if params[:redirect].to_s.truthy? && @users.one? && User.normalize_name(@users.first.name) == User.normalize_name(params[:search][:name_matches]) + redirect_to @users.first else - @users = User.paginated_search(params) - respond_with(@users) + respond_with @users end end diff --git a/app/controllers/wiki_pages_controller.rb b/app/controllers/wiki_pages_controller.rb index 2d3272e95..c55c5eacb 100644 --- a/app/controllers/wiki_pages_controller.rb +++ b/app/controllers/wiki_pages_controller.rb @@ -18,7 +18,7 @@ class WikiPagesController < ApplicationController def index @wiki_pages = WikiPage.paginated_search(params) - if params[:redirect].to_s.truthy? && @wiki_pages.one? + 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) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 3de57bf14..6aee47d3a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -169,8 +169,10 @@ module ApplicationHelper def quick_search_form_for(attribute, url, name, autocomplete: nil, &block) tag.li do search_form_for(url, classes: "quick-search-form one-line-form") do |f| - out = tag.input type: :hidden, name: :redirect, value: "1" - out += f.input attribute, label: false, placeholder: "Search #{name}", input_html: { id: nil, "data-autocomplete": autocomplete } + out = f.input attribute, label: false, placeholder: "Search #{name}", input_html: { id: nil, "data-autocomplete": autocomplete } + out += tag.input type: :hidden, name: :redirect, value: 1 + out += capture { yield f } if block_given? + out end end end diff --git a/app/models/artist.rb b/app/models/artist.rb index 3021403a9..096eb2db0 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -4,6 +4,7 @@ class Artist < ApplicationRecord attr_accessor :url_string_changed array_attribute :other_names + api_attributes including: [:urls] before_validation :normalize_name before_validation :normalize_other_names