<commit_before>= Vidibus::RoutingError

Catches ActionController::RoutingError which does not work with Rails 3
out of the box. It basically catches the exception on Rack-level and
re-raises it on application-level.

This gem is part of the open source service-oriented {video
framework}[http://vidibus.org] Vidibus.


== Addressed Problem

Since Rails 3 is based on Rack, catching a 404 error in your Application
controller does not work as expected. The underlying problem is discussed
{here}[https://rails.lighthouseapp.com/projects/8994/tickets/4444-can-no-longer-rescue_from-actioncontrollerroutingerror].

An easy but insufficient fix for this issue is to define a catch-all route
at the end of your routes.rb:

  match "*path" => "application#rescue_404"

<b>But beware of the major drawback!</b> If your application relies on engines that
extend your app with their own routes, things will break because those
routes will never get fired.

With this gem, all your routing problems should be gone.


== Installation

Add the dependency to the Gemfile of your application:

  gem "vidibus-routing_error"

Then call bundle install on your console.


== Usage

With this gem installed, you are able to handle errors like in past versions
of Rails:

  class ApplicationController < ActionController::Base
    rescue_from ActionController::RoutingError, :with => :rescue_404

    def rescue_404
      # do something
      # IMPORTANT: If you modify this method, you have to restart the server.
    end
  end

Keep in mind that you have to restart your server when changing the rescue-method!

If you want to handle the error in a specific controller, you can also route the path 'routing_error' in routes.rb:

  match 'routing_error', :to => 'my_controller#rescue_404' 

== Underlying Mechanics

This gem implants the middleware Vidibus::RoutingError::Rack into your Rails stack
right after ActionDispatch::ShowExceptions which returns a 404 response if no
matching route was found for the current request.

Vidibus::RoutingError::Rack catches the 404 status and redirects internally to the route
/routing_error which is provided by this gem.

Through this route the method RoutingErrorController#rescue gets called which then raises
a ActionController::RoutingError on application level so you can rescue this error.


== Possible Issues

=== Catch-all Route

If your application has a catch-route, this gem won't work, because routes provided by
engines will be added after any existing routes. If you don't need a catch-all route for
other purposes than rescuing from routing errors, you can savely remove it.


=== Class Caching

Depending on the structure of your application, you might get an error in development
like this:

  TypeError (User can't be referred)

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 provided by some engine. You should be able to get rid of
the error above by turning on class caching. Try it (and restart the server afterwards):

  # development.rb
  config.cache_classes = true

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:

  # top of development.rb
  require "app/models/user"


== Copyright

Copyright (c) 2010 <NAME>. See LICENSE for details.


== Thank you!

The development of this gem was sponsored by Käuferportal: http://www.kaeuferportal.de
<commit_msg>Extended documentation of error handling in a custom controller<commit_after>= Vidibus::RoutingError

Catches ActionController::RoutingError which does not work with Rails 3
out of the box. It basically catches the exception on Rack-level and
re-raises it on application-level.

This gem is part of the open source service-oriented {video
framework}[http://vidibus.org] Vidibus.


== Addressed Problem

Since Rails 3 is based on Rack, catching a 404 error in your Application
controller does not work as expected. The underlying problem is discussed
{here}[https://rails.lighthouseapp.com/projects/8994/tickets/4444-can-no-longer-rescue_from-actioncontrollerroutingerror].

An easy but insufficient fix for this issue is to define a catch-all route
at the end of your routes.rb:

  match "*path" => "application#rescue_404"

<b>But beware of the major drawback!</b> If your application relies on engines that
extend your app with their own routes, things will break because those
routes will never get fired.

With this gem, all your routing problems should be gone.


== Installation

Add the dependency to the Gemfile of your application:

  gem "vidibus-routing_error"

Then call bundle install on your console.


== Usage

With this gem installed, you are able to handle errors like in past versions
of Rails:

  class ApplicationController < ActionController::Base
    rescue_from ActionController::RoutingError, :with => :rescue_404

    def rescue_404
      # do something
      # IMPORTANT: If you modify this method, you have to restart the server.
    end
  end

Keep in mind that you have to restart your server when changing the rescue-method!


== Underlying Mechanics

This gem implants the middleware Vidibus::RoutingError::Rack into your Rails stack
right after ActionDispatch::ShowExceptions which returns a 404 response if no
matching route was found for the current request.

Vidibus::RoutingError::Rack catches the 404 status and redirects internally to the route
"/routing_error" which is provided by this gem.

Through this route the method RoutingErrorController#rescue gets called which then raises
a ActionController::RoutingError on application level so you can rescue this error.

=== Custom controller for error handling

If you want to handle the error in a specific controller, you can also route the path
"/routing_error" in routes.rb:

  match "routing_error" => "my_controller#rescue_404"

The failing URI will be available in the environment variable:

  env["vidibus-routing_error.request_uri"]


== Possible Issues

=== Catch-all Route

If your application has a catch-route, this gem won't work, because routes provided by
engines will be added after any existing routes. If you don't need a catch-all route for
other purposes than rescuing from routing errors, you can savely remove it.


=== Class Caching

Depending on the structure of your application, you might get an error in development
like this:

  TypeError (User can't be referred)

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 provided by some engine. You should be able to get rid of
the error above by turning on class caching. Try it (and restart the server afterwards):

  # development.rb
  config.cache_classes = true

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:

  # top of development.rb
  require "app/models/user"


== Copyright

Copyright (c) 2010 <NAME>. See LICENSE for details.


== Thank you!

The development of this gem was sponsored by Käuferportal: http://www.kaeuferportal.de

{'fraction_non_alphanumeric': 0.05408590885280251, 'fraction_numerical': 0.009167103195390257, 'mean_word_length': 4.482412060301508, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3333948', 'n_tokens_mistral': 2092, 'n_tokens_neox': 1949, 'n_words': 1041}