How to know the action (name) which I am coming from?

Hi there!

What I need is know the action name which I am coming from.

Best regards.

Paco

Hi Paco,

paco.onrails wrote:

What I need is know the action name which I am coming from.

In your view, controller.controller_name and controller.action_name will
tell you which controller or action your view's being rendered from.

Best regards,
Bill

if you’re looking for the previous action, you could parse the controller/action names from request.referer.

RSL

Hi paco, try request.path_parameters.

Best regards.

Leonardo Gómez

Hi,

request.path_parameters returns the current parameters, not the ones
corresponding the previous action.
I haven't been able to find anything better yet than parsing
request.referer or submiting the info through params.

In my case, its an ajax request and i want to render one of various
RJS templates, depending on the form that the user is currenly
displaying.
Any suggestions?

Regards,
Alberto.

Perhaps a hidden input in each of the forms would be best? And then
your Ajax method can render different templates based on that.

-Brady

Yes, I would suggest to use a hidden form field or a simple query
string parameter for this purpose. Evaluating the referer is a risky
business as users can disable this information in their browsers. This
way you would need to implement a fallback scenario for these users.

Max

This sounds like an ideal time to use:
1. hidden fields to manage parameters (I use a from_type, and a from_id
so I can route back to the appropriate form after a create or update -
there are several routes that can create a "scenario" in my app, and I
always want to route back to the model/view that the user is creating
the scenario from, be it the index view for scenarios, or a specific
parent project)

2. A "GenericController" class that sits between a specific model's
controller and ApplicationController. My GenericController implements
all the standard (for my app at least) routing by examining the
from_type and from_id parameters to determine where to redirect the
user. It also handles the standard AR rescues as well.

paco.onrails wrote:

Hi there!

What I need is know the action name which I am coming from.

Best regards.

Paco

checkout request.env["HTTP_REFERER"]. I think it returns the url and you
can then parse that data for the action.

mike