diff --git a/app/assets/javascripts/errors.coffee b/app/assets/javascripts/errors.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/errors.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ef410f0..6adac3d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,4 +1,5 @@ class ApplicationController < ActionController::Base + # include HttpResponseConcern # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception @@ -6,11 +7,22 @@ class ApplicationController < ActionController::Base before_action :authenticate_user! before_action :require_admin_user! + # rescue_from ActiveRecord::RecordNotFound, :with => :page_not_found + # rescue_from StandardError, :with => :internal_server_error + protected def require_admin_user! unless current_user.admin? - redirect_to root_path + request.referrer || root_path end end + + # def page_not_found + # render_404 + # end + + # def internal_server_error + # render_500 + # end end diff --git a/app/controllers/concerns/http_response_concern.rb b/app/controllers/concerns/http_response_concern.rb new file mode 100644 index 0000000..eff0f31 --- /dev/null +++ b/app/controllers/concerns/http_response_concern.rb @@ -0,0 +1,13 @@ +module HttpResponseConcern + extend ActiveSupport::Concern + # this would be more for rendering unauthorized users with status 401 but + # wanted to see your thoughts of perhaps adding something like this + # for external resources that may be used in the future + def render_404 + render file: 'public/404.html', status: 404, layout: false + end + + def render_500 + render file: 'public/500.html', status: 500, layout: false + end +end \ No newline at end of file diff --git a/app/controllers/errors_controller.rb b/app/controllers/errors_controller.rb new file mode 100644 index 0000000..2a6e8ab --- /dev/null +++ b/app/controllers/errors_controller.rb @@ -0,0 +1,9 @@ +class ErrorsController < ApplicationController + def not_found + render file: 'public/404.html', status: 404, layout: true + end + def internal_server_error + render file: 'public/500.html', status: 500, layout: true + end +end + diff --git a/app/helpers/errors_helper.rb b/app/helpers/errors_helper.rb new file mode 100644 index 0000000..8e3b415 --- /dev/null +++ b/app/helpers/errors_helper.rb @@ -0,0 +1,2 @@ +module ErrorsHelper +end diff --git a/config/application.rb b/config/application.rb index f0b73b1..6ab67a1 100644 --- a/config/application.rb +++ b/config/application.rb @@ -22,5 +22,7 @@ class Application < Rails::Application # Do not swallow errors in after_commit/after_rollback callbacks. config.active_record.raise_in_transactional_callbacks = true + + config.exceptions_app = self.routes end end diff --git a/config/environments/development.rb b/config/environments/development.rb index b55e214..e8b439a 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -10,7 +10,8 @@ config.eager_load = false # Show full error reports and disable caching. - config.consider_all_requests_local = true + config.consider_all_requests_local = false + config.action_controller.perform_caching = false # Don't care if the mailer can't send. diff --git a/config/routes.rb b/config/routes.rb index 8ade0c2..f8a4878 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do + resources :common_tasks resources :neighborhoods resources :extracurricular_activities @@ -36,6 +37,9 @@ resources :communications, only: [:new, :show, :create, :edit, :update, :destroy] end + match "/404", :to => "errors#not_found", :via => :all + match "/500", :to => "errors#internal_server_error", :via => :all + resources :locations resources :organizations resources :participations, only: :destroy diff --git a/public/404.html b/public/404.html index b612547..e067e26 100644 --- a/public/404.html +++ b/public/404.html @@ -4,52 +4,14 @@
You may have mistyped the address or the page may have moved.
+The page you have requested does not exist or the page may have moved.
If you are the application owner check the logs for more information.
+