wikis: redirect legacy title param to show page.
Redirect /wiki_pages?title=touhou to /wiki_pages/touhou.
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
class WikiPagesController < ApplicationController
|
class WikiPagesController < ApplicationController
|
||||||
respond_to :html, :xml, :json, :js
|
respond_to :html, :xml, :json, :js
|
||||||
before_action :normalize_search_params, :only => [:index]
|
|
||||||
layout "sidebar"
|
layout "sidebar"
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@@ -15,8 +14,12 @@ class WikiPagesController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@wiki_pages = authorize WikiPage.paginated_search(params)
|
if params[:title].present?
|
||||||
respond_with(@wiki_pages)
|
redirect_to wiki_pages_path(search: { title_normalize: params[:title] }, redirect: true)
|
||||||
|
else
|
||||||
|
@wiki_pages = authorize WikiPage.paginated_search(params)
|
||||||
|
respond_with(@wiki_pages)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def search
|
def search
|
||||||
@@ -90,11 +93,4 @@ class WikiPagesController < ApplicationController
|
|||||||
true
|
true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def normalize_search_params
|
|
||||||
if params[:title]
|
|
||||||
params[:search] ||= {}
|
|
||||||
params[:search][:title] = params.delete(:title)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -31,6 +31,11 @@ class WikiPagesControllerTest < ActionDispatch::IntegrationTest
|
|||||||
assert_response :success
|
assert_response :success
|
||||||
assert_select "tr td:first-child", text: "abc"
|
assert_select "tr td:first-child", text: "abc"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "redirect the legacy title param to the show page" do
|
||||||
|
get wiki_pages_path(title: "abc")
|
||||||
|
assert_redirected_to wiki_pages_path(search: { title_normalize: "abc" }, redirect: true)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "search action" do
|
context "search action" do
|
||||||
|
|||||||
Reference in New Issue
Block a user