wiki pages: replace show_or_new page with redirects.
* Redirect the show_or_new action to either the show page or the new page. Don't use show_or_new to render nonexistent wikis; do that in the regular show action instead. * Make the show action return 404 for nonexistent wikis.
This commit is contained in:
@@ -33,7 +33,8 @@ class WikiPagesController < ApplicationController
|
|||||||
@wiki_page, found_by = WikiPage.find_by_id_or_title(params[:id])
|
@wiki_page, found_by = WikiPage.find_by_id_or_title(params[:id])
|
||||||
|
|
||||||
if request.format.html? && @wiki_page.blank? && found_by == :title
|
if request.format.html? && @wiki_page.blank? && found_by == :title
|
||||||
redirect_to show_or_new_wiki_pages_path(title: params[:id])
|
@wiki_page = WikiPage.new(title: params[:id])
|
||||||
|
respond_with @wiki_page, status: 404
|
||||||
elsif request.format.html? && @wiki_page.present? && found_by == :id
|
elsif request.format.html? && @wiki_page.present? && found_by == :id
|
||||||
redirect_to @wiki_page
|
redirect_to @wiki_page
|
||||||
elsif @wiki_page.blank?
|
elsif @wiki_page.blank?
|
||||||
@@ -69,15 +70,10 @@ class WikiPagesController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def show_or_new
|
def show_or_new
|
||||||
@wiki_page = WikiPage.find_by_title(params[:title])
|
|
||||||
|
|
||||||
if params[:title].blank?
|
if params[:title].blank?
|
||||||
redirect_to new_wiki_page_path(wiki_page_params(:create))
|
redirect_to new_wiki_page_path(wiki_page_params(:create))
|
||||||
elsif @wiki_page.present?
|
|
||||||
redirect_to wiki_page_path(@wiki_page)
|
|
||||||
else
|
else
|
||||||
@wiki_page = WikiPage.new(:title => params[:title])
|
redirect_to wiki_page_path(params[:title])
|
||||||
respond_with(@wiki_page)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,11 @@
|
|||||||
<p><%= wiki_page_other_names_list(@wiki_page) %></p>
|
<p><%= wiki_page_other_names_list(@wiki_page) %></p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= format_text(@wiki_page.body) %>
|
<% if @wiki_page.new_record? %>
|
||||||
|
<p>This wiki page does not exist. <%= link_to "Create new wiki page", new_wiki_page_path(wiki_page: { title: @wiki_page.title }) %>.</p>
|
||||||
|
<% else %>
|
||||||
|
<%= format_text(@wiki_page.body) %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<% if @wiki_page.artist %>
|
<% if @wiki_page.artist %>
|
||||||
<p><%= link_to "View artist", @wiki_page.artist %></p>
|
<p><%= link_to "View artist", @wiki_page.artist %></p>
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
<%= render "sidebar" %>
|
|
||||||
|
|
||||||
<% content_for(:content) do %>
|
|
||||||
<h1 id="wiki-page-title">
|
|
||||||
<%= link_to @wiki_page.pretty_title, posts_path(:tags => @wiki_page.title), :class => "tag-type-#{@wiki_page.category_name}" %>
|
|
||||||
</h1>
|
|
||||||
<div id="wiki-page-body" class="prose">
|
|
||||||
<p>This wiki page does not exist. <%= link_to "Create new wiki page", new_wiki_page_path(:wiki_page => {:title => params[:title]}) %>.</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<% if @wiki_page.artist.present? %>
|
|
||||||
<p><%= link_to "View artist", @wiki_page.artist %></p>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<%= wiki_page_alias_and_implication_list(@wiki_page)%>
|
|
||||||
|
|
||||||
<%= wiki_page_post_previews(@wiki_page) %>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<%= render "secondary_links" %>
|
|
||||||
|
|
||||||
<% content_for(:page_title) do %>
|
|
||||||
Wiki - <%= params[:title] %> - <%= Danbooru.config.app_name %>
|
|
||||||
<% end %>
|
|
||||||
@@ -66,9 +66,11 @@ class WikiPagesControllerTest < ActionDispatch::IntegrationTest
|
|||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
should "redirect html requests for a nonexistent title" do
|
should "show the 'does not exist' page for a nonexistent title" do
|
||||||
get wiki_page_path("what")
|
get wiki_page_path("what")
|
||||||
assert_redirected_to(show_or_new_wiki_pages_path(title: "what"))
|
|
||||||
|
assert_response 404
|
||||||
|
assert_select "#wiki-page-body", text: /This wiki page does not exist/
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return 404 to api requests for a nonexistent title" do
|
should "return 404 to api requests for a nonexistent title" do
|
||||||
@@ -98,9 +100,9 @@ class WikiPagesControllerTest < ActionDispatch::IntegrationTest
|
|||||||
assert_redirected_to(@wiki_page)
|
assert_redirected_to(@wiki_page)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "render when given a nonexistent title" do
|
should "redirect when given a nonexistent title" do
|
||||||
get show_or_new_wiki_pages_path, params: { title: "what" }
|
get show_or_new_wiki_pages_path, params: { title: "what" }
|
||||||
assert_response :success
|
assert_redirected_to wiki_page_path("what")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user