I have a couple action inside my cart_controller. I have 2 views inside /carts: payment.html.erb
and pay.html.erb
def pay
success = #do something that returns true or false
if success
respond_to do |format|
format.html { redirect_to '/cart/checkout/review'}
end
else
render_errors
end
end
def render_errors
respond_to do |format|
format.html { render 'payment'}
end
end
What i expect is that when
success == false
it hits render_errors and renders the payment view
then stop. However what it's doing is: it's rendering the payment view
AND THEN it renders the pay view
as well. So the payment view
is never shown. What am doing wrong? I'm using Ruby 2.0 on Rails 4.0.
UPDATE:
I found out that whenever I do @cart.errors.add(:name, 'error message')
the pay view
is rendered regardless of any return
or respond_to
statements. Any idea?