Created
January 18, 2010 10:25
-
-
Save tomlea/279926 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module RaisableRedirections | |
def self.included(other) | |
other.send(:around_filter, :handle_raisable_redirections) | |
end | |
protected | |
def raise_redirect_to(*args) | |
raise Redirect.new(*args) | |
end | |
private | |
class Redirect < Exception | |
attr_reader :redirect_params | |
def initialize(*args) | |
@redirect_params = args | |
end | |
end | |
def handle_raisable_redirections | |
begin | |
yield | |
rescue Redirect => r | |
redirect_to *r.redirect_params | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment