From fc57578c8572ac5edcd41f1bccdd7134405ae6b4 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 20 May 2013 17:28:32 +1000 Subject: [PATCH] proper 404 for json request 404 --- app/controllers/application_controller.rb | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 88427ee163f..4206e46a5f0 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -66,12 +66,17 @@ class ApplicationController < ActionController::Base rescue_from Discourse::NotFound do - f = Topic.where(deleted_at: nil, archetype: "regular") - @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, layout: 'no_js', template: '/exceptions/not_found' + if request.format && request.format.json? + render status: 404, layout: false, text: "[error: 'not found']" + else + f = Topic.where(deleted_at: nil, archetype: "regular") + @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, layout: 'no_js', template: '/exceptions/not_found' + end + end rescue_from Discourse::InvalidAccess do