Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/assets/javascripts/errors.coffee
Original file line number Diff line number Diff line change
@@ -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/
14 changes: 13 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
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

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
13 changes: 13 additions & 0 deletions app/controllers/concerns/http_response_concern.rb
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions app/controllers/errors_controller.rb
Original file line number Diff line number Diff line change
@@ -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

2 changes: 2 additions & 0 deletions app/helpers/errors_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ErrorsHelper
end
2 changes: 2 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Rails.application.routes.draw do

resources :common_tasks
resources :neighborhoods
resources :extracurricular_activities
Expand Down Expand Up @@ -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
Expand Down
55 changes: 9 additions & 46 deletions public/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,14 @@
<title>The page you were looking for doesn't exist (404)</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
body {
background-color: #EFEFEF;
color: #2E2F30;
text-align: center;
font-family: arial, sans-serif;
margin: 0;
}

div.dialog {
width: 95%;
max-width: 33em;
margin: 4em auto 0;
}

div.dialog > div {
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #BBB;
border-top: #B00100 solid 4px;
border-top-left-radius: 9px;
border-top-right-radius: 9px;
background-color: white;
padding: 7px 12% 0;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}

h1 {
font-size: 100%;
color: #730E15;
line-height: 1.5em;
margin: 0 auto;
position: initial;
}

div.dialog > p {
margin: 0 0 1em;
padding: 1em;
background-color: #F7F7F7;
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #999;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border-top-color: #DADADA;
color: #666;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
p {
font-size: 20px;
margin: 30px;
}
</style>
</head>
Expand All @@ -58,10 +20,11 @@
<!-- This file lives in public/404.html -->
<div class="dialog">
<div>
<h1>The page you were looking for doesn't exist.</h1>
<p>You may have mistyped the address or the page may have moved.</p>
<img src="http://www.clker.com/cliparts/y/O/8/Z/l/C/blue-graduation-cap.svg"></img>
<h1>It looks like nothing was found at this location</h1>
<p>The page you have requested does not exist or the page may have moved.</p>
</div>
<p>If you are the application owner check the logs for more information.</p>
<p><a href="javascript:history.back()">Go Back</a></p>
</div>
</body>
</html>
53 changes: 8 additions & 45 deletions public/500.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,14 @@
<title>We're sorry, but something went wrong (500)</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
body {
background-color: #EFEFEF;
color: #2E2F30;
text-align: center;
font-family: arial, sans-serif;
margin: 0;
}

div.dialog {
width: 95%;
max-width: 33em;
margin: 4em auto 0;
}

div.dialog > div {
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #BBB;
border-top: #B00100 solid 4px;
border-top-left-radius: 9px;
border-top-right-radius: 9px;
background-color: white;
padding: 7px 12% 0;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}

h1 {
font-size: 100%;
color: #730E15;
line-height: 1.5em;
margin: 0 auto;
position: initial;
}

div.dialog > p {
margin: 0 0 1em;
padding: 1em;
background-color: #F7F7F7;
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #999;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border-top-color: #DADADA;
color: #666;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
p {
font-size: 20px;
margin: 30px;
}
</style>
</head>
Expand All @@ -58,9 +20,10 @@
<!-- This file lives in public/500.html -->
<div class="dialog">
<div>
<h1>We're sorry, but something went wrong.</h1>
<img src="http://media.inktastic.com/thumbnail/500/968/41/41968500.1.png"></img>
<h1>The request was unsuccessful due to an unexpected condition encountered by the server.</h1>
</div>
<p>If you are the application owner check the logs for more information.</p>
<p><a href='/'>Take me back</a></p>
</div>
</body>
</html>
17 changes: 17 additions & 0 deletions test/controllers/errors_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'test_helper'

class ErrorsControllerTest < ActionController::TestCase
include Devise::TestHelpers
test "should get not_found" do
get :not_found
assert true
assert_response :redirect
end

test "should get internal_server_error" do
get :internal_server_error
assert true
assert_response :redirect
end

end