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

**URL:** <https://www.ruby-forum.com/t/best-practices-passing-referring-controller-action/70314>\
**Category:** Rails\
**Created:** [September 28, 2006, 5:06am UTC](https://www.ruby-forum.com/t/best-practices-passing-referring-controller-action/70314 "2006-09-28T05:06:49Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sw0rdfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/edb3f5/32.png) [@sw0rdfish](https://www.ruby-forum.com/u/sw0rdfish)\
**Post date:** [September 28, 2006, 5:06am UTC](https://www.ruby-forum.com/t/best-practices-passing-referring-controller-action/70314/1 "2006-09-28T05:06:49Z")

</div>

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](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!

---

<div class="post-metadata">

**Author:** ![sw0rdfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/edb3f5/32.png) [@sw0rdfish](https://www.ruby-forum.com/u/sw0rdfish)\
**Post date:** [September 28, 2006, 6:41am UTC](https://www.ruby-forum.com/t/best-practices-passing-referring-controller-action/70314/2 "2006-09-28T06:41:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sw0rdfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/edb3f5/32.png) [@sw0rdfish](https://www.ruby-forum.com/u/sw0rdfish)\
**Post date:** [September 28, 2006, 4:20pm UTC](https://www.ruby-forum.com/t/best-practices-passing-referring-controller-action/70314/3 "2006-09-28T16:20:02Z")

</div>

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 🙂

Thanks guys!

---

<div class="post-metadata">

**Author:** ![sw0rdfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/edb3f5/32.png) [@sw0rdfish](https://www.ruby-forum.com/u/sw0rdfish)\
**Post date:** [September 28, 2006, 4:22pm UTC](https://www.ruby-forum.com/t/best-practices-passing-referring-controller-action/70314/4 "2006-09-28T16:22:03Z")

</div>

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 🙂

Thanks guys!

---

<div class="post-metadata">

**Author:** ![sw0rdfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/edb3f5/32.png) [@sw0rdfish](https://www.ruby-forum.com/u/sw0rdfish)\
**Post date:** [September 28, 2006, 4:34pm UTC](https://www.ruby-forum.com/t/best-practices-passing-referring-controller-action/70314/5 "2006-09-28T16:34:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sw0rdfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/edb3f5/32.png) [@sw0rdfish](https://www.ruby-forum.com/u/sw0rdfish)\
**Post date:** [September 28, 2006, 5:40pm UTC](https://www.ruby-forum.com/t/best-practices-passing-referring-controller-action/70314/6 "2006-09-28T17:40:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sw0rdfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/edb3f5/32.png) [@sw0rdfish](https://www.ruby-forum.com/u/sw0rdfish)\
**Post date:** [September 28, 2006, 5:18pm UTC](https://www.ruby-forum.com/t/best-practices-passing-referring-controller-action/70314/7 "2006-09-28T17:18:23Z")

</div>

On 28 September 2006 18:28, sw0rdfish wrote:

> 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.

---

<div class="post-metadata">

**Author:** ![sw0rdfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/edb3f5/32.png) [@sw0rdfish](https://www.ruby-forum.com/u/sw0rdfish)\
**Post date:** [September 29, 2006, 8:21am UTC](https://www.ruby-forum.com/t/best-practices-passing-referring-controller-action/70314/8 "2006-09-29T08:21:20Z")

</div>

redirect\_back\_or\_default :action =\> ‘action’

It comes with the login generator, but

> **[BigBold - Informasi Tentang Bisnis dan Marketing](http://www.bigbold.com)**
>
> BigBold ialah situs yang memberikan segala macam Informasi Tentang Bisnis dan Marketing

Vish
