# Is there a built in variable for the current path?

**URL:** <https://www.ruby-forum.com/t/is-there-a-built-in-variable-for-the-current-path/140622>\
**Category:** Rails\
**Created:** [June 16, 2008, 9:27pm UTC](https://www.ruby-forum.com/t/is-there-a-built-in-variable-for-the-current-path/140622 "2008-06-16T21:27:46Z")\
**Posts on this page:** 4\
**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:** [June 16, 2008, 9:27pm UTC](https://www.ruby-forum.com/t/is-there-a-built-in-variable-for-the-current-path/140622/1 "2008-06-16T21:27:46Z")

</div>

Probably a silly question, but I’m trying to create a partial that I  
use in two seperate resources… one is called Tickets and one is  
TicketsSearch.

I have links at the top of the page that order my seatrch by passing a  
parameter into the ticket\_path() variable…

Now I’d like to change that to the current path so that in  
TicketsSearch I can use the same parameter and it would be like  
saying

tickets\_search\_path( :order =\> date ) instead of ticket\_path( :order  
=\> date ) w/o having to create an if statements and have two blocks of  
table headers…

I hope that makes sense. Here’s my table header view if it helps.

[http://pastie.textmate.org/private/dtth3tyeso8dluicug](http://pastie.textmate.org/private/dtth3tyeso8dluicug)

Thanks!

---

<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:** [June 16, 2008, 9:36pm UTC](https://www.ruby-forum.com/t/is-there-a-built-in-variable-for-the-current-path/140622/2 "2008-06-16T21:36:36Z")

</div>

oops… I was messing around trying stuff in that last pastie, I  
forgot to fix it…

so ignore that base\_path variable, or just look here…

[http://pastie.textmate.org/private/4mho1rh36jpqejzprctdtg](http://pastie.textmate.org/private/4mho1rh36jpqejzprctdtg)

thanks 🙂

---

<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:** [June 16, 2008, 10:11pm UTC](https://www.ruby-forum.com/t/is-there-a-built-in-variable-for-the-current-path/140622/3 "2008-06-16T22:11:35Z")

</div>

Ok I figured it out… after trying 100 different things…

url\_for() does the trick for me.

request.request\_uri returns the entire path including current query  
strings, which I don’t want… nad I can’t pass t new query strings,  
but url\_for allows you to pass it an action, controller and  
query\_strings, and if you leave the action or controller out, it uses  
the current one, which is perfect 🙂 now if I’m on the search, I get

[http://0.0.0.0:3000/tickets\_searches/2?order\_by=tickets.date](http://0.0.0.0:3000/tickets_searches/2?order_by=tickets.date)

and if I’m on the ticket listing… I get

[http://0.0.0.0:3000/tickets/?order\_by=tickets.date](http://0.0.0.0:3000/tickets/?order_by=tickets.date)

sweet! 🙂

( just posting here for google achieving 🙂 )

---

<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:** [June 16, 2008, 11:56pm UTC](https://www.ruby-forum.com/t/is-there-a-built-in-variable-for-the-current-path/140622/4 "2008-06-16T23:56:31Z")

</div>

if you were using restful routing, just prefix the route with \_url  
rather  
than \_path:

blogs\_path

becomes

blogs\_url
