forked from e621ng/e621ng
Merge pull request #631 from DonovanDMC/wikipages-normalize-title
[WikiPages] normalize title in show_or_new & edit
This commit is contained in:
commit
40ff649250
@ -15,7 +15,7 @@ class WikiPagesController < ApplicationController
|
||||
if params[:id] =~ /\A\d+\z/
|
||||
@wiki_page = WikiPage.find(params[:id])
|
||||
else
|
||||
@wiki_page = WikiPage.find_by_title(params[:id])
|
||||
@wiki_page = WikiPage.titled(params[:id])
|
||||
if @wiki_page.nil? && request.format.symbol == :html
|
||||
redirect_to show_or_new_wiki_pages_path(:title => params[:id])
|
||||
return
|
||||
@ -51,7 +51,7 @@ class WikiPagesController < ApplicationController
|
||||
if params[:id] =~ /\A\d+\z/
|
||||
@wiki_page = WikiPage.find(params[:id])
|
||||
else
|
||||
@wiki_page = WikiPage.titled(params[:id]).first
|
||||
@wiki_page = WikiPage.titled(params[:id])
|
||||
end
|
||||
|
||||
if @wiki_page.present?
|
||||
@ -96,7 +96,7 @@ class WikiPagesController < ApplicationController
|
||||
end
|
||||
|
||||
def show_or_new
|
||||
@wiki_page = WikiPage.find_by_title(params[:title])
|
||||
@wiki_page = WikiPage.titled(params[:title])
|
||||
if @wiki_page
|
||||
redirect_to wiki_page_path(@wiki_page)
|
||||
else
|
||||
|
@ -55,6 +55,6 @@ class RelatedTagQuery
|
||||
end
|
||||
|
||||
def wiki_page
|
||||
WikiPage.titled(query).first
|
||||
WikiPage.titled(query)
|
||||
end
|
||||
end
|
||||
|
@ -351,9 +351,9 @@ class Artist < ApplicationRecord
|
||||
end
|
||||
|
||||
def update_wiki
|
||||
if persisted? && saved_change_to_name? && attribute_before_last_save("name").present? && WikiPage.titled(attribute_before_last_save("name")).exists?
|
||||
if persisted? && saved_change_to_name? && attribute_before_last_save("name").present? && WikiPage.titled(attribute_before_last_save("name"))
|
||||
# we're renaming the artist, so rename the corresponding wiki page
|
||||
old_page = WikiPage.titled(name_before_last_save).first
|
||||
old_page = WikiPage.titled(name_before_last_save)
|
||||
if wiki_page.nil?
|
||||
# a wiki page doesn't already exist for the new name, so rename the old one
|
||||
old_page.update(title: name, body: @notes || old_page.body)
|
||||
|
@ -50,7 +50,7 @@ class WikiPage < ApplicationRecord
|
||||
|
||||
module SearchMethods
|
||||
def titled(title)
|
||||
where("title = ?", title.downcase.tr(" ", "_"))
|
||||
find_by(title: title.downcase.tr(" ", "_"))
|
||||
end
|
||||
|
||||
def active
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
|
||||
<div class="dtext-container">
|
||||
<%= format_text(WikiPage.titled(Danbooru.config.flag_notice_wiki_page).first.try(&:body)) %>
|
||||
<%= format_text(WikiPage.titled(Danbooru.config.flag_notice_wiki_page)&.body) %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
<div class="replace-image-dialog-body">
|
||||
<div class="dtext-container">
|
||||
<%= format_text(WikiPage.titled(Danbooru.config.replacement_notice_wiki_page).first.try(&:body)) %>
|
||||
<%= format_text(WikiPage.titled(Danbooru.config.replacement_notice_wiki_page)&.body) %>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
@ -60,9 +60,7 @@ class WikiPageTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "search by title" do
|
||||
matches = WikiPage.titled("hot potato")
|
||||
assert_equal(1, matches.count)
|
||||
assert_equal("hot_potato", matches.first.title)
|
||||
assert_equal("hot_potato", WikiPage.titled("hot potato").title)
|
||||
end
|
||||
|
||||
should "search other names with wildcards" do
|
||||
|
Loading…
Reference in New Issue
Block a user