[rspec-users] redirect_to(:action => 'foo') and return

Courtenay court3nay at gmail.com
Sat Dec 30 18:55:59 EST 2006

I'm not sure why this is happening, but if I do this in a controller

    unless @variation && @variation.quantity > 0
      flash[:error] = "Sorry, that product is currently not available."
      redirect_to(:action => 'error') and return

rspec tells me

  ActionController::DoubleRenderError in 'The Carts controller with an
existing User should add items to the cart'
Render and/or redirect were called multiple times in this action.
Please note that you may only call render OR redirect, and only once
per action. Also note that neither redirect nor render terminate
execution of the action, so if you want to exit an action after
redirecting, you need to do something like "redirect_to(...) and
return". Finally, note that to cause a before filter to halt execution
of the rest of the filter chain, the filter must return false,
explicitly, so "render(...) and return false".

however if I change that to

      redirect_to(:action => 'error')

it works just fine.  All versions of "..and return" seem to fail.


More information about the rspec-users mailing list