whats-wrong 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 91bd3b17e6ced0f331d647ab6e4af48ecb7d5e2b
4
- data.tar.gz: 2118c26e584586184d3ec3e04a356cf22aab3a8b
3
+ metadata.gz: dd032a34c586c27f96fa14cf7d6263c3fc9c0696
4
+ data.tar.gz: 245c037378081cd69c6720aca0a8c5e43251411a
5
5
  SHA512:
6
- metadata.gz: af8927c6e99a10fb2060520222b0ae3527b94615bf5951f8f9a4e24aab34aed53ef3f64e027c382425396445e320a3aec8ff3b1c7486193044821c020f5c3059
7
- data.tar.gz: a895301b8ded48d4054b34c7e4c9070fb15a5496b0f170f7d35b60f470f88805c73d21c464344351860c131374e96220ab3a893e9bd4455b779b29073e6953af
6
+ metadata.gz: 06a86262a053cab1d61912497bd0d875e65e7464bf96150a4646d4d4f61795360ef63ef169d339115ae620b8b20b4811334c7d6ec86c8ab8bcf947dbc6cc75b0
7
+ data.tar.gz: 4ba4a9ca05500a91640fb80e961fb5909b344f4d0f7daa39ced49f8b0ea7978bebdb486a30c505dcb05294548f395fe85a6f56003dfd1ce1cc4d9d67aed8cce2
data/README.md CHANGED
@@ -11,7 +11,7 @@ gem 'whats-wrong'
11
11
  ## Usage
12
12
 
13
13
 
14
- #### Generate static pages for your locale
14
+ #### Solution 1: Generate static pages for your locale
15
15
 
16
16
  ```ruby
17
17
  rails g whats_wrong:pages zh-CN
@@ -23,6 +23,32 @@ rails g whats_wrong:pages zh-CN
23
23
 
24
24
  Supported locales: en, zh-CN.
25
25
 
26
+ #### Solution 2: or Render with dynamic error pages
27
+
28
+ Maybe static pages couldn't fit your necessary. Enable this feature If you want to render error pages with layout.
29
+
30
+ ```ruby
31
+ rails g whats_wrong:install
32
+ ```
33
+
34
+ Then the default error pages will be rendered within your layout.
35
+
36
+
37
+ ##### Custom error pages
38
+
39
+ Also you can custom error pages(include 404, 422 and 500).
40
+
41
+ ```html
42
+ <!-- app/views/exceptions/404.html.erb -->
43
+ <p>The page you were looking for doesn't exist.</p>
44
+
45
+
46
+ <!-- some helper methods you can use -->
47
+ <p><%= status %></p> <!-- 404 or others -->
48
+ <p><%= original_path %></p> <!-- which path case error before render error page -->
49
+ <p><%= exception %></p><!-- which exception case error -->
50
+ ```
51
+
26
52
  ## Contributing
27
53
  Contribution translations go here https://www.localeapp.com/projects/9397 .
28
54
 
@@ -1,11 +1,23 @@
1
1
  class WhatsWrong::ExceptionsController < ApplicationController
2
+ # TODO: layout
3
+
4
+ helper_method :status, :exception, :original_path
2
5
 
3
6
  def show
4
- exception = env['action_dispatch.exception']
5
- path_info = request.path_info
6
- status = path_info[1..-1].to_i
7
- original_path = env["action_dispatch.original_path"]
8
- render plain: "status: #{status}, origin_path: #{original_path}"
7
+ render "exceptions/#{status}", status: status
8
+ end
9
+
10
+ protected
11
+ def status
12
+ @status ||= request.path_info[1..-1].to_i
13
+ end
14
+
15
+ def exception
16
+ request.env['action_dispatch.exception']
17
+ end
18
+
19
+ def original_path
20
+ request.env["action_dispatch.original_path"]
9
21
  end
10
22
 
11
23
  end
@@ -0,0 +1 @@
1
+ 404 Not Found
@@ -0,0 +1 @@
1
+ 422 Unprocessable Entity
@@ -0,0 +1 @@
1
+ 500 Internal Server Error
@@ -1,3 +1,3 @@
1
1
  module WhatsWrong
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whats-wrong
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - bastengao
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-16 00:00:00.000000000 Z
11
+ date: 2016-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -49,6 +49,9 @@ files:
49
49
  - README.md
50
50
  - Rakefile
51
51
  - app/controllers/whats_wrong/exceptions_controller.rb
52
+ - app/views/exceptions/404.html.erb
53
+ - app/views/exceptions/422.html.erb
54
+ - app/views/exceptions/500.html.erb
52
55
  - config/locales/en.yml
53
56
  - config/locales/zh-CN.yml
54
57
  - lib/generators/whats_wrong/install_generator.rb