Here is a code similar to one I have. What I need to do is to redirect from a nested method to other page and stop execution all actions it was called from. In this this case it’s method2. It should redirect to '/home/index' and I need to prevent redirecting to '/home/index123'
class MyController::ApplicationController
def index
#some work
method1
#some work that must be done if there is no redirect
#some work that must be done if there is no redirect
redirect_to '/home/index123'
end
private
def method1
#some work
method2
#some work that must be done if there is no redirect
#some work that must be done if there is no redirect
end
def method2
#some work
#I need to redirect to other page just from here!
redirect_to '/home/index'
end
end
Your ideas?
Make your redirection a variable. Set this variable as the return value of your method.
For instance: