get rid of nonsense 404.html
correct 404 handling for invalid pages
This commit is contained in:
parent
18b00d01d0
commit
80fb20816c
|
@ -65,14 +65,13 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
rescue_from Discourse::NotFound do
|
rescue_from Discourse::NotFound do
|
||||||
if !request.format || request.format.html?
|
|
||||||
# for now do a simple remap, we may look at cleaner ways of doing the render
|
f = Topic.where(deleted_at: nil, archetype: "regular")
|
||||||
#
|
@latest = f.order('views desc').take(10)
|
||||||
# Sam: I am confused about this, we need a comment that explains why this is conditional
|
@recent = f.order('created_at desc').take(10)
|
||||||
raise ActiveRecord::RecordNotFound
|
@slug = params[:slug].class == String ? params[:slug] : ''
|
||||||
else
|
@slug.gsub!('-',' ')
|
||||||
render file: 'public/404', formats: [:html], layout: false, status: 404
|
render status: 404, layout: 'no_js', template: '/exceptions/not_found'
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
rescue_from Discourse::InvalidAccess do
|
rescue_from Discourse::InvalidAccess do
|
||||||
|
|
|
@ -1,14 +1,9 @@
|
||||||
class ExceptionsController < ApplicationController
|
class ExceptionsController < ApplicationController
|
||||||
skip_before_filter :check_xhr
|
skip_before_filter :check_xhr
|
||||||
layout 'no_js'
|
|
||||||
|
|
||||||
def not_found
|
def not_found
|
||||||
f = Topic.where(deleted_at: nil, archetype: "regular")
|
# centralize all rendering of 404 into app controller
|
||||||
|
raise Discourse::NotFound
|
||||||
|
end
|
||||||
|
|
||||||
@latest = f.order('views desc').take(10)
|
|
||||||
@recent = f.order('created_at desc').take(10)
|
|
||||||
@slug = params[:slug].class == String ? params[:slug] : ''
|
|
||||||
@slug.gsub!('-',' ')
|
|
||||||
render status: 404
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,7 +21,7 @@ class StaticController < ApplicationController
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
render file: 'public/404', layout: false, status: 404
|
raise Discourse::NotFound
|
||||||
end
|
end
|
||||||
|
|
||||||
# This method just redirects to a given url.
|
# This method just redirects to a given url.
|
||||||
|
|
|
@ -25,7 +25,10 @@ class TopicsController < ApplicationController
|
||||||
caches_action :avatar, cache_path: Proc.new {|c| "#{c.params[:post_number]}-#{c.params[:topic_id]}" }
|
caches_action :avatar, cache_path: Proc.new {|c| "#{c.params[:post_number]}-#{c.params[:topic_id]}" }
|
||||||
|
|
||||||
def show
|
def show
|
||||||
create_topic_view
|
opts = params.slice(:username_filters, :best_of, :page, :post_number, :posts_before, :posts_after, :best)
|
||||||
|
@topic_view = TopicView.new(params[:id] || params[:topic_id], current_user, opts)
|
||||||
|
|
||||||
|
raise Discourse::NotFound unless @topic_view.posts.present?
|
||||||
|
|
||||||
anonymous_etag(@topic_view.topic) do
|
anonymous_etag(@topic_view.topic) do
|
||||||
redirect_to_correct_topic && return if slugs_do_not_match
|
redirect_to_correct_topic && return if slugs_do_not_match
|
||||||
|
@ -196,11 +199,6 @@ class TopicsController < ApplicationController
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def create_topic_view
|
|
||||||
opts = params.slice(:username_filters, :best_of, :page, :post_number, :posts_before, :posts_after, :best)
|
|
||||||
@topic_view = TopicView.new(params[:id] || params[:topic_id], current_user, opts)
|
|
||||||
end
|
|
||||||
|
|
||||||
def toggle_mute(v)
|
def toggle_mute(v)
|
||||||
@topic = Topic.where(id: params[:topic_id].to_i).first
|
@topic = Topic.where(id: params[:topic_id].to_i).first
|
||||||
guardian.ensure_can_see!(@topic)
|
guardian.ensure_can_see!(@topic)
|
||||||
|
|
|
@ -286,6 +286,9 @@ class TopicView
|
||||||
post_count = (filtered_post_ids.length - 1)
|
post_count = (filtered_post_ids.length - 1)
|
||||||
|
|
||||||
max = [max, post_count].min
|
max = [max, post_count].min
|
||||||
|
|
||||||
|
return @posts = [] if min > max
|
||||||
|
|
||||||
min = [[min, max].min, 0].max
|
min = [[min, max].min, 0].max
|
||||||
|
|
||||||
@index_offset = min
|
@index_offset = min
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>The resource you wanted can't be found (404)</title>
|
|
||||||
<style type="text/css">
|
|
||||||
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
|
||||||
div.dialog {
|
|
||||||
width: 25em;
|
|
||||||
padding: 0 4em;
|
|
||||||
margin: 4em auto 0 auto;
|
|
||||||
border: 1px solid #ccc;
|
|
||||||
border-right-color: #999;
|
|
||||||
border-bottom-color: #999;
|
|
||||||
}
|
|
||||||
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<!-- This file lives in public/422.html -->
|
|
||||||
<div class="dialog">
|
|
||||||
<h1>The resource you want can't be found.</h1>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -227,20 +227,11 @@ describe TopicView do
|
||||||
describe '#filter_posts_paged' do
|
describe '#filter_posts_paged' do
|
||||||
before { SiteSetting.stubs(:posts_per_page).returns(1) }
|
before { SiteSetting.stubs(:posts_per_page).returns(1) }
|
||||||
|
|
||||||
it 'returns correct posts for first page' do
|
it 'returns correct posts for all pages' do
|
||||||
topic_view.filter_posts_paged(1).should == [p1, p2]
|
topic_view.filter_posts_paged(1).should == [p1, p2]
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns correct posts for requested page number' do
|
|
||||||
topic_view.filter_posts_paged(2).should == [p2, p3]
|
topic_view.filter_posts_paged(2).should == [p2, p3]
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns correct posts for last page' do
|
|
||||||
topic_view.filter_posts_paged(4).should == [p5]
|
topic_view.filter_posts_paged(4).should == [p5]
|
||||||
end
|
topic_view.filter_posts_paged(100).should == []
|
||||||
|
|
||||||
it 'returns posts for last page when page is out of range' do
|
|
||||||
topic_view.filter_posts_paged(100).should == [p5]
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue