Q about returning to the action that called the method

I have a few actions which, after completing, i want to return to the
action that called them. Currently the way i’m doing this is passsing
through a parameter with the name of the calling method, eg

<%= link_to ‘Delete this picture’, :action => ‘delete_picture’, :id =>
picture, :came_from => “edit_story” %>

Then in the callee method i refer to this in the redirect_to part:

redirect_to :action => params[:came_from], :id => @story if
params[:came_from]
flash[:warning] = “Couldn’t find a story to return to, returning to
list”
redirect_to :action => “list”

Is there a nicer way to get the calling method, without having to
remember to explicitly pass it through? Or a nicer alternative to what
i’m doing, generally?

thanks
max

Max W. wrote:

Is there a nicer way to get the calling method, without having to
remember to explicitly pass it through? Or a nicer alternative to what
i’m doing, generally?

thanks
max

try to mess around with redirect_to :back and see if it helps you…

M^

(continuing Mikkel’s post)

redirect_to :back

(taken from api)

back: Back to the page that issued the request. Useful for forms that
are triggered from multiple places. Short-hand for
redirect_to(request.env[“HTTP_REFERER”])

The redirection happens as a “302 Moved” header.

When using redirect_to :back, if there is no referrer, RedirectBackError
will be raised. You may specify some fallback behavior for this case by
rescueing RedirectBackError.

( Peak Obsession
)

Mikkel B. wrote:

try to mess around with redirect_to :back and see if it helps you…

Trying this made me realise that when i delete a picture, i actually
need to go back TWO steps, not just one. So i think i’m better off
sticking with my explicit parameter passing method to avoid confusion.

“redirect_to :back” is good to know though, might be useful in future.
Thanks!