# Console for Testing Routes?

**URL:** <https://www.ruby-forum.com/t/console-for-testing-routes/93539>\
**Category:** Rails\
**Created:** [April 4, 2006, 4:06pm UTC](https://www.ruby-forum.com/t/console-for-testing-routes/93539 "2006-04-04T16:06:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ingoweiss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/77aa72/32.png) [@ingoweiss](https://www.ruby-forum.com/u/ingoweiss)\
**Post date:** [April 4, 2006, 4:06pm UTC](https://www.ruby-forum.com/t/console-for-testing-routes/93539/1 "2006-04-04T16:06:51Z")

</div>

Hi,

when the “Agile Web D.” book talks about routes, there are what  
looks like console transcripts like the following:

URL\> store  
@params = {:controller =\> ‘store’, :action = ‘index’}

Is there something like a console for testing routes (where you could  
put in a url and see how rails would route it)??

Ingo

---

<div class="post-metadata">

**Author:** ![ingoweiss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/77aa72/32.png) [@ingoweiss](https://www.ruby-forum.com/u/ingoweiss)\
**Post date:** [April 4, 2006, 6:19pm UTC](https://www.ruby-forum.com/t/console-for-testing-routes/93539/2 "2006-04-04T18:19:01Z")

</div>

I’m pretty sure that dave just created that for demonstration purposes  
but the latest rails as the app object in the console which you can  
use for this:

./script/console

> > app.url\_for :controller =\> ‘store’, :action =\> ‘index’  
> > =\> “[http://www.example.com/store](http://www.example.com/store)”  
> > app.host! ‘www.snowdevil.ca’  
> > =\> “www.snowdevil.ca”  
> > app.url\_for :controller =\> ‘store’, :action =\> ‘index’  
> > =\> “[http://www.snowdevil.ca/store](http://www.snowdevil.ca/store)”

On 4/4/06, Ingo W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Ingo
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Tobi  
[http://shopify.com](http://shopify.com) - modern e-commerce software  
[http://typo.leetsoft.com](http://typo.leetsoft.com) - Open source weblog engine  
[http://blog.leetsoft.com](http://blog.leetsoft.com) - Technical weblog

---

<div class="post-metadata">

**Author:** ![ingoweiss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/77aa72/32.png) [@ingoweiss](https://www.ruby-forum.com/u/ingoweiss)\
**Post date:** [April 4, 2006, 7:47pm UTC](https://www.ruby-forum.com/t/console-for-testing-routes/93539/3 "2006-04-04T19:47:52Z")

</div>

Is there any way to do that sort of thing from a controller? Giving  
some function a path and then getting the params that path would  
produce?

For example, passing this to some function:

“/store/edit/1”

and getting back

[:controller =\> “store”, :action =\> “edit”, :id =\> “1”]

or whatever the appropriate params for the route are.

– Michael D.

---

<div class="post-metadata">

**Author:** ![ingoweiss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/77aa72/32.png) [@ingoweiss](https://www.ruby-forum.com/u/ingoweiss)\
**Post date:** [April 4, 2006, 9:01pm UTC](https://www.ruby-forum.com/t/console-for-testing-routes/93539/4 "2006-04-04T21:01:25Z")

</div>

ruby script/console  
Loading development environment.  
app.get \>\> app.get ‘/’  
=\> 200

> > app.controller.params  
> > =\> {“action”=\>“index”, “controller”=\>“shop”}

On 4/4/06, Michael D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > when the “Agile Web D.” book talks about routes, there are  
> > Rails mailing list  
> > removed\_email\_address@domain.invalid  
> > [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Tobi  
[http://shopify.com](http://shopify.com) - modern e-commerce software  
[http://typo.leetsoft.com](http://typo.leetsoft.com) - Open source weblog engine  
[http://blog.leetsoft.com](http://blog.leetsoft.com) - Technical weblog

---

<div class="post-metadata">

**Author:** ![ingoweiss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/77aa72/32.png) [@ingoweiss](https://www.ruby-forum.com/u/ingoweiss)\
**Post date:** [April 5, 2006, 2:36am UTC](https://www.ruby-forum.com/t/console-for-testing-routes/93539/5 "2006-04-05T02:36:02Z")

</div>

I’ve seen that, which is good, but I mean from within an action in a  
controller or elsewhere, not from the console.

At some point, my application gets lists of URLs, and I want to know  
what params their paths produce.

(Plus, oops! Those should have been curly braces.)

– Michael D.

On Apr 4, 2006, at 12:00 PM, Tobias Lütke wrote:

---

<div class="post-metadata">

**Author:** ![ingoweiss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/77aa72/32.png) [@ingoweiss](https://www.ruby-forum.com/u/ingoweiss)\
**Post date:** [April 5, 2006, 7:32am UTC](https://www.ruby-forum.com/t/console-for-testing-routes/93539/6 "2006-04-05T07:32:38Z")

</div>

This is great! Thanks!!

Ingo

> ruby script/console  
> Loading development environment.  
> app.get \>\> app.get ‘/’  
> =\> 200
> 
> > > app.controller.params  
> > > =\> {“action”=\>“index”, “controller”=\>“shop”}

---

<div class="post-metadata">

**Author:** ![ingoweiss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/77aa72/32.png) [@ingoweiss](https://www.ruby-forum.com/u/ingoweiss)\
**Post date:** [April 5, 2006, 8:40am UTC](https://www.ruby-forum.com/t/console-for-testing-routes/93539/7 "2006-04-05T08:40:41Z")

</div>

Michael D. wrote:

> I’ve seen that, which is good, but I mean from within an action in a  
> controller or elsewhere, not from the console.
> 
> At some point, my application gets lists of URLs, and I want to know  
> what params their paths produce.

This might help:

[http://clarkware.com/cgi/blosxom/2006/04/04#HeadlessApp](http://clarkware.com/cgi/blosxom/2006/04/04#HeadlessApp)

–

Ray
