Permalink
Browse files

Merge branch 'dynamic_error_pages'

  • Loading branch information...
JeskTop committed Sep 5, 2014
2 parents 9dbe35b + 6873e01 commit 62c7d6e15f9c14d9d111a6a25ceb841b33a7db24
@@ -12,6 +12,7 @@
@import "home/products.css.scss";
@import "home/user.css.scss";
@import "home/notifications.css.scss";
+@import "home/errors.css.scss";
$nprogress-color: $primary-color;
@import 'nprogress';
@@ -0,0 +1,7 @@
+.errors-container {
+ width: 700px;
+ margin-right: auto;
+ margin-left: auto;
+ text-align: center;
+ color: $primary-color;
+}
@@ -0,0 +1,11 @@
+class ErrorsController < ApplicationController
+ def show
+ render status_code.to_s, status: status_code
+ end
+
+ protected
+
+ def status_code
+ params[:code] || 500
+ end
+end
@@ -0,0 +1,10 @@
+<div class="errors-container">
+ <div>
+ <h1>404</h1>
+ <hr>
+ <p class="lead">很抱歉,您要访问的页面不存在!</p>
+ <p class="lead">
+ <%= link_to "回到首页", root_path, class: "btn btn-lg btn-primary" %>
+ </p>
+ </div>
+</div>
@@ -0,0 +1,10 @@
+<div class="errors-container">
+ <div>
+ <h1>422</h1>
+ <hr>
+ <p class="lead">很抱歉,请求格式正确,但是由于含有语义错误,无法响应。</p>
+ <p class="lead">
+ <%= link_to "回到首页", root_path, class: "btn btn-lg btn-primary" %>
+ </p>
+ </div>
+</div>
@@ -0,0 +1,10 @@
+<div class="errors-container">
+ <div>
+ <h1>500</h1>
+ <hr>
+ <p class="lead">很抱歉,服务器遇到了一个未曾预料的状况,导致了它无法完成对请求的处理。</p>
+ <p class="lead">
+ <%= link_to "回到首页", root_path, class: "btn btn-lg btn-primary" %>
+ </p>
+ </div>
+</div>
View
@@ -26,5 +26,6 @@ class Application < Rails::Application
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
config.i18n.default_locale = "zh-CN"
+ config.exceptions_app = self.routes
end
end
View
@@ -19,6 +19,10 @@
resources :evaluates
end
+ %w( 404 422 500 ).each do |code|
+ get code, to: "errors#show", code: code
+ end
+
resources :products, only: [:index, :show] do
resources :messages, only: [:index, :create, :destroy] do
View
@@ -1,58 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <title>The page you were looking for doesn't exist (404)</title>
- <style>
- body {
- background-color: #EFEFEF;
- color: #2E2F30;
- text-align: center;
- font-family: arial, sans-serif;
- }
-
- div.dialog {
- width: 25em;
- margin: 4em auto 0 auto;
- 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 4em 0 4em;
- }
-
- h1 {
- font-size: 100%;
- color: #730E15;
- line-height: 1.5em;
- }
-
- body > p {
- width: 33em;
- margin: 0 auto 1em;
- padding: 1em 0;
- background-color: #F7F7F7;
- border: 1px solid #CCC;
- border-right-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);
- }
- </style>
-</head>
-
-<body>
- <!-- This file lives in public/404.html -->
- <div class="dialog">
- <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>
- </div>
- <p>If you are the application owner check the logs for more information.</p>
-</body>
-</html>
View
@@ -1,58 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <title>The change you wanted was rejected (422)</title>
- <style>
- body {
- background-color: #EFEFEF;
- color: #2E2F30;
- text-align: center;
- font-family: arial, sans-serif;
- }
-
- div.dialog {
- width: 25em;
- margin: 4em auto 0 auto;
- 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 4em 0 4em;
- }
-
- h1 {
- font-size: 100%;
- color: #730E15;
- line-height: 1.5em;
- }
-
- body > p {
- width: 33em;
- margin: 0 auto 1em;
- padding: 1em 0;
- background-color: #F7F7F7;
- border: 1px solid #CCC;
- border-right-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);
- }
- </style>
-</head>
-
-<body>
- <!-- This file lives in public/422.html -->
- <div class="dialog">
- <h1>The change you wanted was rejected.</h1>
- <p>Maybe you tried to change something you didn't have access to.</p>
- </div>
- <p>If you are the application owner check the logs for more information.</p>
-</body>
-</html>
View
@@ -1,57 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <title>We're sorry, but something went wrong (500)</title>
- <style>
- body {
- background-color: #EFEFEF;
- color: #2E2F30;
- text-align: center;
- font-family: arial, sans-serif;
- }
-
- div.dialog {
- width: 25em;
- margin: 4em auto 0 auto;
- 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 4em 0 4em;
- }
-
- h1 {
- font-size: 100%;
- color: #730E15;
- line-height: 1.5em;
- }
-
- body > p {
- width: 33em;
- margin: 0 auto 1em;
- padding: 1em 0;
- background-color: #F7F7F7;
- border: 1px solid #CCC;
- border-right-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);
- }
- </style>
-</head>
-
-<body>
- <!-- This file lives in public/500.html -->
- <div class="dialog">
- <h1>We're sorry, but something went wrong.</h1>
- </div>
- <p>If you are the application owner check the logs for more information.</p>
-</body>
-</html>

0 comments on commit 62c7d6e

Please sign in to comment.