For example, I have something like this in my controller:
def save
...
render 'error' if user.nil?
@cast = user.cast
render 'cast'
end
I have nil: no method error here (in user.cast). But if I use redirect_to instead of render, everything works perfectly.
It seems like Rails doesn’t stop their executive stack after render, but stops after redirect_to. Doesn’t it?
Your assumption is correct.
redirect_tosends an HTTP 302 redirect message to the user’s browser, telling it to go to a different URL, thus stopping your current execution.I’d reccommend checking out this post: http://blog.markusproject.org/?p=3313
He gives a great summary of how to use each: