On Thu, Nov 19, 2009 at 2:39 PM, candlerb <b.cand...@pobox.com> wrote:

> Is there a standard way in Rails of terminating a request early with
> throw or raise?
>
>
Why do you need to terminate a request early?  Is this an HTTP request?

-Conrad


> I am thinking of when a controller invokes a private method and inside
> that method I wish to render a result and then finish. For example:
>
>  def my_action
>    ...
>    authorize_something
>    ...
>  end
>
> private
>  def authorize_something
>    ...
>    if some_failure_condition
>      flash[:error] = "I couldn't do that"
>      redirect_to :controller=>:top, :action=>:index
>      throw :request_complete    # <<< WHAT GOES HERE?
>    end
>  end
>
> that is, without having to put an explicit catch or rescue in every
> action which calls authorize_something, and without having to check
> the return value from authorize_something everywhere that it is
> called.
>
> I have found 'rescue_from'; however this doesn't do what I need
> because my Cucumber tests still abort with the exception. That is, it
> seems that rescue_from is intended to handle pretty display of error
> pages when "real" exceptions occur, not as a mechanism by which a user
> exception can signal the early (but successful) termination of a
> request.
>
> Is there any other facility I should be looking at?
>
> Many thanks,
>
> Brian.
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonrails-t...@googlegroups.com.
> To unsubscribe from this group, send email to
> rubyonrails-talk+unsubscr...@googlegroups.com<rubyonrails-talk%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=.
>
>
>

--

You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=.


Reply via email to