better 404 handling by forcing html format for unknowns

This commit is contained in:
2016-06-15 12:48:58 +02:00
parent 2221ad8d79
commit 23bd4c9a58
2 changed files with 11 additions and 1 deletions
+1
View File
@@ -1,3 +1,4 @@
sudo: false
rvm: rvm:
- 2.3.1 - 2.3.1
services: services:
+10 -1
View File
@@ -27,7 +27,16 @@ module Cmtool
def not_found def not_found
@page = ::Page.find_by_name_and_locale('404', I18n.locale.to_s) || ::Page.new(name: '404', body: "404 Page Not Found") @page = ::Page.find_by_name_and_locale('404', I18n.locale.to_s) || ::Page.new(name: '404', body: "404 Page Not Found")
@sub_pages = [] @sub_pages = []
render template: 'pages/404', layout: @page.layout.presence || ::Page.layouts.first.to_s, status: 404 page_name_extension = params[:name].to_s[/(?<=\.)\w{2,4}$/]
format = %w[html css js json].find{|f| f == request.format.symbol.to_s or f == page_name_extension }.try(:to_sym) || :html
case format
when :json
render json: {}, status: 404
when :html
render template: 'pages/404', formats: [:html], layout: @page.layout.presence || ::Page.layouts.first.to_s, status: 404
else
render nothing: true, status: 404
end
end end
def sitemap def sitemap