Skip to content

Instantly share code, notes, and snippets.

@tomlea
Created January 18, 2010 10:25
Show Gist options
  • Save tomlea/279926 to your computer and use it in GitHub Desktop.
Save tomlea/279926 to your computer and use it in GitHub Desktop.
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