# Rails method to get the current url that called the action?

**URL:** <https://www.ruby-forum.com/t/rails-method-to-get-the-current-url-that-called-the-action/89541>\
**Category:** Rails\
**Created:** [March 21, 2007, 2:20am UTC](https://www.ruby-forum.com/t/rails-method-to-get-the-current-url-that-called-the-action/89541 "2007-03-21T02:20:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mixplate](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@mixplate](https://www.ruby-forum.com/u/mixplate)\
**Post date:** [March 21, 2007, 2:20am UTC](https://www.ruby-forum.com/t/rails-method-to-get-the-current-url-that-called-the-action/89541/1 "2007-03-21T02:20:46Z")

</div>

hi, i implemented a captcha and basically need to redisplay the page  
with the fetched information.

im trying redirect\_to :back after the captcha is valid, but i think its  
going back in history. so basically i need to find a way to recapture  
the url that called the check captcha function.

thoughts?

thanks.

---

<div class="post-metadata">

**Author:** ![mixplate](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@mixplate](https://www.ruby-forum.com/u/mixplate)\
**Post date:** [March 21, 2007, 1:59pm UTC](https://www.ruby-forum.com/t/rails-method-to-get-the-current-url-that-called-the-action/89541/2 "2007-03-21T13:59:28Z")

</div>

when i use render :action, i lose the url that i specified in my routes.  
hmmm, or maybe i can just create a new route for the check…

---

<div class="post-metadata">

**Author:** ![mixplate](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@mixplate](https://www.ruby-forum.com/u/mixplate)\
**Post date:** [March 21, 2007, 7:29pm UTC](https://www.ruby-forum.com/t/rails-method-to-get-the-current-url-that-called-the-action/89541/3 "2007-03-21T19:29:12Z")

</div>

This is in a controller right? You should be able to use  
request.request\_uri…

b

---

<div class="post-metadata">

**Author:** ![mixplate](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@mixplate](https://www.ruby-forum.com/u/mixplate)\
**Post date:** [March 21, 2007, 7:36pm UTC](https://www.ruby-forum.com/t/rails-method-to-get-the-current-url-that-called-the-action/89541/4 "2007-03-21T19:36:12Z")

</div>

2007/3/21, mixplate [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):  
\<…\>

> im trying redirect\_to :back after the captcha is valid, but i think its  
> going back in history. so basically i need to find a way to recapture  
> the url that called the check captcha function.
> 
> thoughts?

redirect\_to :back should do exactly what you need - it works on  
information contained  
in http referef header, so it should go back to the page which  
originated the request.  
From the source:

when :back  
request.env[“HTTP\_REFERER”] ?  
redirect\_to(request.env[“HTTP\_REFERER”]) : raise(RedirectBackError)

## Regards, Rimantas

[http://rimantas.com/](http://rimantas.com/)
