views:

78

answers:

3

In my Rails controller I want to branch to a different controller's action, show its view and then return back to my original action, i.e. it's not a simple redirect, more like a sub-procedure call.

I want to use this whenever a user does something suspicious, like editing a post too often in a row. I still want to allow the edit, but first the user has to answer some CAPTCHA-like questions on a different page. (Similar to Authlogic-oid, where during validation the user is redirected to the OpenID provider's page)

A: 

You can't.

Convert the common stuff into a helper method and then both the controllers should call this method.

Neeraj Singh
What aboud Authlogic-oid? It redirects to the OpenID provider's page during the validation and then returns. (At least it looks that way, the internals might work different)
DR
Authlogic-oid uses modules. Modules are like classes, only they don't have instances. You mix them into a class (such as your controller) to gain their functionality. Lot's of gems use them.
Jarrod
In my case, what would be the "common stuff"?
DR
I think he was talking about shared code. Anything used in more than one place.
Jarrod
Yes, I believe so, too, but what has that to do with my question? That's why I ask for a little bit more clarification.
DR
A: 

It's possible to create an instance of the other controller and call methods on it, but you should probably reevaluate your organization first (look into helpers, modules, etc.)

@my_other_controller = MyOtherController.new

@my_other_controller.some_method(params[:id])
Jarrod
+2  A: 

You can push the current request into the Session, then do a redirect to the captcha, then have the captcha action look into the Session to check where it should redirect to.

IIRC, Autlogic does exactly that with redirect_back_or_default.

Leonid Shevtsov