# Redirect depending on where the action has been triggered

**URL:** <https://www.ruby-forum.com/t/redirect-depending-on-where-the-action-has-been-triggered/188190>\
**Category:** Rails\
**Created:** [May 7, 2010, 11:13am UTC](https://www.ruby-forum.com/t/redirect-depending-on-where-the-action-has-been-triggered/188190 "2010-05-07T11:13:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gregm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bc79bd/32.png) [@gregm](https://www.ruby-forum.com/u/gregm)\
**Post date:** [May 7, 2010, 11:13am UTC](https://www.ruby-forum.com/t/redirect-depending-on-where-the-action-has-been-triggered/188190/1 "2010-05-07T11:13:39Z")

</div>

Hi,  
I am working on a newsletter module. you can subscribe to the newsletter  
at many different place on the website and they all trigged the create  
action on the newsletter controller.  
I would to redirect to where the action has been triggered. How can I do  
so?  
Should I create an action in each controller that save the subscription?

Greg

---

<div class="post-metadata">

**Author:** ![gregm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bc79bd/32.png) [@gregm](https://www.ruby-forum.com/u/gregm)\
**Post date:** [May 7, 2010, 11:57am UTC](https://www.ruby-forum.com/t/redirect-depending-on-where-the-action-has-been-triggered/188190/2 "2010-05-07T11:57:26Z")

</div>

Once the user of your application chooses to subscribe to your  
newsletter then the create action will be called within the newsletter  
controller. To redirect to the action that triggered the create  
process what you can do is use:

```
redirect_to request.env['HTTP_REFERER']

```

This will redirect to the previous action and this will be the action  
that triggered create.

---

<div class="post-metadata">

**Author:** ![gregm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bc79bd/32.png) [@gregm](https://www.ruby-forum.com/u/gregm)\
**Post date:** [May 7, 2010, 1:15pm UTC](https://www.ruby-forum.com/t/redirect-depending-on-where-the-action-has-been-triggered/188190/3 "2010-05-07T13:15:08Z")

</div>

> ```
> redirect_to request.env['HTTP_REFERER']
> 
> ```

Great!
