# How to get last url?

**URL:** <https://www.ruby-forum.com/t/how-to-get-last-url/185827>\
**Category:** Rails\
**Created:** [March 26, 2010, 7:17pm UTC](https://www.ruby-forum.com/t/how-to-get-last-url/185827 "2010-03-26T19:17:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rutisyrz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/848f3c/32.png) [@rutisyrz](https://www.ruby-forum.com/u/rutisyrz)\
**Post date:** [March 26, 2010, 7:17pm UTC](https://www.ruby-forum.com/t/how-to-get-last-url/185827/1 "2010-03-26T19:17:44Z")

</div>

Dear all,

How can I get lastly accessed url on my current page.  
i.e. user is on ‘Posts’ page & now if user wants to add new post for  
that user needs to login first… for that user 'll be redirected to  
login page…Now after getting logged in successfully user must be  
redirected to the ‘Posts’ page again so that now he can add new post…

Thanking you…

---

<div class="post-metadata">

**Author:** ![rutisyrz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/848f3c/32.png) [@rutisyrz](https://www.ruby-forum.com/u/rutisyrz)\
**Post date:** [March 26, 2010, 7:24pm UTC](https://www.ruby-forum.com/t/how-to-get-last-url/185827/2 "2010-03-26T19:24:07Z")

</div>

On Fri, Mar 26, 2010 at 2:17 PM, Rutvij P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Dear all,
> 
> How can I get lastly accessed url on my current page.  
> i.e. user is on ‘Posts’ page & now if user wants to add new post for  
> that user needs to login first… for that user 'll be redirected to  
> login page…Now after getting logged in successfully user must be  
> redirected to the ‘Posts’ page again so that now he can add new post…

In a controller you can do request.url

–  
Rick DeNatale

Blog: [http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)  
Twitter: [http://twitter.com/RickDeNatale](http://twitter.com/RickDeNatale)  
WWR: [http://www.workingwithrails.com/person/9021-rick-denatale](http://www.workingwithrails.com/person/9021-rick-denatale)  
LinkedIn: [http://www.linkedin.com/in/rickdenatale](http://www.linkedin.com/in/rickdenatale)

---

<div class="post-metadata">

**Author:** ![rutisyrz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/848f3c/32.png) [@rutisyrz](https://www.ruby-forum.com/u/rutisyrz)\
**Post date:** [March 26, 2010, 8:04pm UTC](https://www.ruby-forum.com/t/how-to-get-last-url/185827/3 "2010-03-26T20:04:28Z")

</div>

Rick Denatale wrote:

> On Fri, Mar 26, 2010 at 2:17 PM, Rutvij P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > ï¿½How can I get lastly accessed url on my current page.  
> > ï¿½i.e. user is on ‘Posts’ page & now if user wants to add new post for  
> > that user needs to login first… for that user 'll be redirected to  
> > login page…Now after getting logged in successfully user must be  
> > redirected to the ‘Posts’ page again so that now he can add new post…
> 
> In a controller you can do request.url

You should also seriously consider using one of the authentication gems  
that are available. They already solve this issue and many more. No need  
to roll your own authentication system with all the options available.

I see that a lot of people seem to like AuthLogic, there is also Devise,  
and several others.

> **[GitHub - binarylogic/authlogic: A simple ruby authentication solution.](https://github.com/binarylogic/authlogic)**
>
> A simple ruby authentication solution. Contribute to binarylogic/authlogic development by creating an account on GitHub.

> **[GitHub - heartcombo/devise: Flexible authentication solution for Rails with...](https://github.com/heartcombo/devise)**
>
> Flexible authentication solution for Rails with Warden. - GitHub - heartcombo/devise: Flexible authentication solution for Rails with Warden.
