vidibus-routing_error 0.1.5 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +55 -3
- data/VERSION +1 -1
- data/app/controllers/routing_error_controller.rb +3 -3
- data/lib/vidibus-routing_error.rb +1 -1
- data/lib/vidibus/routing_error/rack.rb +5 -9
- data/vidibus-routing_error.gemspec +15 -17
- metadata +7 -8
- data/.gitignore +0 -21
data/README.rdoc
CHANGED
@@ -1,8 +1,29 @@
|
|
1
1
|
= vidibus-routing_error
|
2
2
|
|
3
|
-
|
3
|
+
Catches ActionController::RoutingError which does not work with Rails 3
|
4
|
+
out of the box. It basically catches the exception on Rack-level and
|
5
|
+
re-raises it on application-level.
|
4
6
|
|
5
|
-
|
7
|
+
This gem is part of the open source service-oriented {video
|
8
|
+
framework}[http://vidibus.org] Vidibus.
|
9
|
+
|
10
|
+
|
11
|
+
== Addressed Problem
|
12
|
+
|
13
|
+
Since Rails 3 is based on Rack, catching a 404 error in your Application
|
14
|
+
controller does not work as expected. The underlying problem is discussed
|
15
|
+
{here}[https://rails.lighthouseapp.com/projects/8994/tickets/4444-can-no-longer-rescue_from-actioncontrollerroutingerror].
|
16
|
+
|
17
|
+
An easy but insufficient fix for this issue is to define a catch-all route
|
18
|
+
at the end of your routes.rb:
|
19
|
+
|
20
|
+
match "*a", :to => "application#rescue_404"
|
21
|
+
|
22
|
+
*But beware of the major drawback!* If your application relies on engines that
|
23
|
+
extend your app with their own routes, things will break because those
|
24
|
+
routes will never get fired.
|
25
|
+
|
26
|
+
With this gem, all your routing problems should be gone.
|
6
27
|
|
7
28
|
|
8
29
|
== Installation
|
@@ -16,7 +37,8 @@ Then call bundle install on your console.
|
|
16
37
|
|
17
38
|
== Usage
|
18
39
|
|
19
|
-
With this gem installed, you are able to handle errors like in past versions
|
40
|
+
With this gem installed, you are able to handle errors like in past versions
|
41
|
+
of Rails:
|
20
42
|
|
21
43
|
class ApplicationController < ActionController::Base
|
22
44
|
rescue_from ActionController::RoutingError, :with => :rescue_404
|
@@ -30,6 +52,36 @@ With this gem installed, you are able to handle errors like in past versions of
|
|
30
52
|
Keep in mind that you have to restart your server when changing the rescue-method!
|
31
53
|
|
32
54
|
|
55
|
+
== Underlying Mechanics
|
56
|
+
|
57
|
+
This gem implants the middleware Vidibus::RoutingError::Rack into your Rails stack
|
58
|
+
right after ActionDispatch::ShowExceptions which returns a 404 response if no
|
59
|
+
matching route was found for the current request.
|
60
|
+
|
61
|
+
Vidibus::RoutingError::Rack catches the 404 status and redirects internally to the route
|
62
|
+
/routing_error which is provided by this gem.
|
63
|
+
|
64
|
+
Through this route the method RoutingErrorController#rescue gets called which then raises
|
65
|
+
a ActionController::RoutingError on application level so you can rescue this error.
|
66
|
+
|
67
|
+
|
68
|
+
== Possible Issues
|
69
|
+
|
70
|
+
Depending on the structure of your application, you might get an error in development like this:
|
71
|
+
|
72
|
+
TypeError (User can't be referred)
|
73
|
+
|
74
|
+
This error is caused by some caching-reloading madness: The middleware implanted by this gem is cached. But in development, your classes usually aren't. Thus some classes may not be available under certain circumstances, e.g. if you are using before filters for user authentication. You should be able to get rid of the error above by turning on class caching. Try it (and restart the server afterwards):
|
75
|
+
|
76
|
+
# development.rb
|
77
|
+
config.cache_classes = true
|
78
|
+
|
79
|
+
If the error is gone, you're lucky as I am. But since it is not feasible to cache classes in development, turn off class caching again and explicitly require the class that couldn't be referred. In my case, it's the user class:
|
80
|
+
|
81
|
+
# top of development.rb
|
82
|
+
require "app/models/user"
|
83
|
+
|
84
|
+
|
33
85
|
== Copyright
|
34
86
|
|
35
87
|
Copyright (c) 2010 Andre Pankratz. See LICENSE for details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -3,13 +3,13 @@ class RoutingErrorController < ApplicationController
|
|
3
3
|
# Re-raise routing_error that has been catched in rack app.
|
4
4
|
# To rescue this error, use default actions:
|
5
5
|
#
|
6
|
-
# rescue_from ActionController::RoutingError, :with => :
|
7
|
-
# def
|
6
|
+
# rescue_from ActionController::RoutingError, :with => :rescue_404
|
7
|
+
# def rescue_404
|
8
8
|
# # do something
|
9
9
|
# end
|
10
10
|
#
|
11
11
|
def rescue
|
12
12
|
env["REQUEST_URI"] = env["vidibus-routing_error.request_uri"]
|
13
|
-
raise env["
|
13
|
+
raise ActionController::RoutingError, "No route matches #{env["REQUEST_URI"].inspect}"
|
14
14
|
end
|
15
15
|
end
|
@@ -4,7 +4,7 @@ require "routing_error/rack"
|
|
4
4
|
module Vidibus::RoutingError
|
5
5
|
class Engine < ::Rails::Engine
|
6
6
|
unless Rails.env.test?
|
7
|
-
config.app_middleware.
|
7
|
+
config.app_middleware.insert_after("ActionDispatch::ShowExceptions", "Vidibus::RoutingError::Rack")
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
@@ -6,18 +6,14 @@ module Vidibus
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def call(env)
|
9
|
-
|
10
|
-
|
11
|
-
rescue => exception
|
12
|
-
if exception.kind_of?(ActionController::RoutingError)
|
13
|
-
env["vidibus-routing_error.exception"] = exception
|
9
|
+
response = @app.call(env)
|
10
|
+
if response[0] == 404
|
14
11
|
env["vidibus-routing_error.request_uri"] = env["REQUEST_URI"]
|
15
|
-
|
16
|
-
# set routing_error path internally to catch route
|
17
12
|
env["PATH_INFO"] = env["REQUEST_URI"] = "/routing_error"
|
13
|
+
@app.call(env)
|
14
|
+
else
|
15
|
+
response
|
18
16
|
end
|
19
|
-
env["action_dispatch.show_exceptions"] = true
|
20
|
-
return @app.call(env)
|
21
17
|
end
|
22
18
|
end
|
23
19
|
end
|
@@ -1,38 +1,36 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{vidibus-routing_error}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Andre Pankratz"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-03-18}
|
13
13
|
s.description = %q{Catches ActionController::RoutingError and sends it to a custom method.}
|
14
14
|
s.email = %q{andre@vidibus.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
|
-
|
17
|
+
"README.rdoc"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
"vidibus-routing_error.gemspec"
|
21
|
+
"LICENSE",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"app/controllers/routing_error_controller.rb",
|
26
|
+
"config/routes.rb",
|
27
|
+
"lib/vidibus-routing_error.rb",
|
28
|
+
"lib/vidibus/routing_error/rack.rb",
|
29
|
+
"spec/spec.opts",
|
30
|
+
"spec/spec_helper.rb",
|
31
|
+
"vidibus-routing_error.gemspec"
|
33
32
|
]
|
34
33
|
s.homepage = %q{http://github.com/vidibus/vidibus-routing_error}
|
35
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
36
34
|
s.require_paths = ["lib"]
|
37
35
|
s.rubygems_version = %q{1.3.7}
|
38
36
|
s.summary = %q{Catches ActionController::RoutingError in Rails 3.}
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vidibus-routing_error
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andre Pankratz
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-03-18 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -88,7 +88,6 @@ extra_rdoc_files:
|
|
88
88
|
- README.rdoc
|
89
89
|
files:
|
90
90
|
- .document
|
91
|
-
- .gitignore
|
92
91
|
- LICENSE
|
93
92
|
- README.rdoc
|
94
93
|
- Rakefile
|
@@ -105,8 +104,8 @@ homepage: http://github.com/vidibus/vidibus-routing_error
|
|
105
104
|
licenses: []
|
106
105
|
|
107
106
|
post_install_message:
|
108
|
-
rdoc_options:
|
109
|
-
|
107
|
+
rdoc_options: []
|
108
|
+
|
110
109
|
require_paths:
|
111
110
|
- lib
|
112
111
|
required_ruby_version: !ruby/object:Gem::Requirement
|