# Redirect Issue

**URL:** <https://www.ruby-forum.com/t/redirect-issue/110341>\
**Category:** Rails\
**Created:** [July 25, 2007, 3:34pm UTC](https://www.ruby-forum.com/t/redirect-issue/110341 "2007-07-25T15:34:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![turnkeytraders](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ba8739/32.png) [@turnkeytraders](https://www.ruby-forum.com/u/turnkeytraders)\
**Post date:** [July 25, 2007, 3:34pm UTC](https://www.ruby-forum.com/t/redirect-issue/110341/1 "2007-07-25T15:34:45Z")

</div>

Hello,

I have a page where anyone can edit some content on it, but they must be  
logged in before doing so. Now, when the person clicks on my “edit”  
action, they are automatically redirected to the login form. Then the  
person logs in, but when they log in, I would like to have them  
redirected to the page where they wanted to edit the content on. How can  
I do that?

Thanks,  
M.

---

<div class="post-metadata">

**Author:** ![turnkeytraders](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ba8739/32.png) [@turnkeytraders](https://www.ruby-forum.com/u/turnkeytraders)\
**Post date:** [July 26, 2007, 12:45am UTC](https://www.ruby-forum.com/t/redirect-issue/110341/2 "2007-07-26T00:45:53Z")

</div>

Use a before\_filter for the edit action? See,  
[http://api.rubyonrails.org/classes/ActionController/Filters/ClassMethods.html](http://api.rubyonrails.org/classes/ActionController/Filters/ClassMethods.html)

On Jul 25, 3:34 pm, Matthew L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![turnkeytraders](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ba8739/32.png) [@turnkeytraders](https://www.ruby-forum.com/u/turnkeytraders)\
**Post date:** [July 26, 2007, 12:46am UTC](https://www.ruby-forum.com/t/redirect-issue/110341/3 "2007-07-26T00:46:14Z")

</div>

On 7/25/07, Matthew L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hello,
> 
> I have a page where anyone can edit some content on it, but they must be  
> logged in before doing so. Now, when the person clicks on my “edit”  
> action, they are automatically redirected to the login form. Then the  
> person logs in, but when they log in, I would like to have them  
> redirected to the page where they wanted to edit the content on. How can  
> I do that?

The basic idea is that before you redirect to the login page, you  
stash away request.request\_uri somewhere. (The session[] object is  
handy, or you can put it in a hidden field in the login form).

Then, when they’ve successfully authenticated, grab the saved uri and  
redirect to there. (You’ll need some kind of default place to go in  
case they don’t come to the login page via a redirect.)

I suggest you look at acts\_as\_authenticated  
([http://agilewebdevelopment.com/plugins/acts\_as\_authenticated](http://agilewebdevelopment.com/plugins/acts_as_authenticated)). It  
provides this capability built in. If nothing else, you can look at  
his code and see how it’s done.

---

<div class="post-metadata">

**Author:** ![turnkeytraders](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ba8739/32.png) [@turnkeytraders](https://www.ruby-forum.com/u/turnkeytraders)\
**Post date:** [July 26, 2007, 1:22am UTC](https://www.ruby-forum.com/t/redirect-issue/110341/4 "2007-07-26T01:22:18Z")

</div>

Great thanks alot!
