Skip to content

Instantly share code, notes, and snippets.

@tomlea
Created January 18, 2010 10:25

Revisions

  1. tomlea revised this gist Jan 18, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion raisable_redirections.rb
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@ def raise_redirect_to(*args)
    class Redirect < Exception
    attr_reader :redirect_params
    def initialize(*args)
    self.redirect_params = args
    @redirect_params = args
    end
    end

  2. tomlea created this gist Jan 18, 2010.
    28 changes: 28 additions & 0 deletions raisable_redirections.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    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)
    self.redirect_params = args
    end
    end

    def handle_raisable_redirections
    begin
    yield
    rescue Redirect => r
    redirect_to *r.redirect_params
    end
    end

    end