Best Practices.... passing referring controller / action.

Hello folk...

I'm wondering what the best practice is for passing referring actions
to a new action. For example if I have an action that I use a million
times in my application I want to be able to call it, and then be
returned to the action that called it... whatever it may be.

Currently I'm using parameters.... When I call the method with a
link_to for example, I do something like this in the view...

<%= link_to 'do this' :action => 'do_this_action', :id =>
@id_of_something, :from_controller => params[:controller], :from_action
=> params[:action] %>

now... I'm 100% sure that's not the way I should do it, because the URL
becomes....

http://0.0.0.0/controller/action/1?from_controller=refering_controller&from_action=ref_action

and then everyone knows the names of my actions... not only is it
messy.... I'm sure there's some security issues there too...

I guess I could pass these things to a session, is that the best way?
Thanks in advance guys!

sw0rdfish пишет:

I'm wondering what the best practice is for passing referring actions
to a new action. For example if I have an action that I use a million
times in my application I want to be able to call it, and then be
returned to the action that called it... whatever it may be.

I guess I could pass these things to a session, is that the best way?
Thanks in advance guys!

People use session to store the url where you need to return to. You can retrieve it with request.request_uri

So you would store the entire URL, and not just the action /
controller?

And request.request_uri returns the current URL?

Anyone else have input on this? Not that I don't trust Maxim, just
more opions the better :slight_smile:

Thanks guys!

So you would store the entire URL, and not just the action /
controller?

And request.request_uri returns the current URL?

Anyone else have input on this? Not that I don't trust Maxim, just
more opions the better :slight_smile:

Thanks guys!

I was looking around the recepie book, and it talks of using...

request.env["HTTP_REFERER"]

Would that work?

P.S. sorry for the double post previosuly. Google went wonky on me.

I was looking around the recepie book, and it talks of using...

request.env["HTTP_REFERER"]

HTTP_REFERER is URL from which the HTTP request came (what page linked to
current page).

Would that work?

It depends on what do you want to store: current request URL or the one, from
where user came to current page.

Well the ultimate goal is to be able to go back to the action I came
from once I'm finished in the "current" action.

Eg.

View an Order -> call action "edit item name" -> go back to view order
OR
view and ITEM -> call action "edit item name" -> go back to view ITEM

I want the action "edit item name" to be the same one for both calls,
so I need to save the action I was in prior to calling "edit item
name"...

I think putting a filter action in the aplication.rb file that runs
before each action calll to store the refering action / controller into
a session would be a good way of doing it.

redirect_back_or_default :action => ‘action’

It comes with the login generator, but http://www.bigbold.com/snippets/posts/show/1052

Vish