# RESTful Routes

**URL:** <https://www.ruby-forum.com/t/restful-routes/123208>\
**Category:** Rails\
**Created:** [December 14, 2007, 10:40pm UTC](https://www.ruby-forum.com/t/restful-routes/123208 "2007-12-14T22:40:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 14, 2007, 10:40pm UTC](https://www.ruby-forum.com/t/restful-routes/123208/1 "2007-12-14T22:40:32Z")

</div>

I have purchased the peepcode tutorial on RESTful and I have to say it  
is brilliant, one thing it does not answer is this question though.

I have been experimenting with rails on nothing serious and managed to  
setup an application for which the routes did which for example did,

[www.myapplication.com/company\_name](http://www.myapplication.com/company_name)

therefore [www.myapplication.com/google](http://www.myapplication.com/google) would pull up googles profile  
from the database

I have looked at RESTful and that suggests  
[www.myapplication.com/companies/company\_name](http://www.myapplication.com/companies/company_name)  
would be the RESTful way to do it, does that mean using RESTful style  
routes I cannot achieve the configuration “[www.myapplication.com/](http://www.myapplication.com/)  
company\_name”?

Or am I just a rails n00b whos missed the point of RESTful?

Thanks for any help anyone can give me!

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 15, 2007, 1:06am UTC](https://www.ruby-forum.com/t/restful-routes/123208/2 "2007-12-15T01:06:33Z")

</div>

removed\_email\_address@domain.invalid wrote:

> I have purchased the peepcode tutorial on RESTful and I have to say it  
> is brilliant, one thing it does not answer is this question though.
> 
> I have been experimenting with rails on nothing serious and managed to  
> setup an application for which the routes did which for example did,
> 
> [www.myapplication.com/company\_name](http://www.myapplication.com/company_name)
> 
> therefore [www.myapplication.com/google](http://www.myapplication.com/google) would pull up googles profile  
> from the database
> 
> I have looked at RESTful and that suggests  
> [www.myapplication.com/companies/company\_name](http://www.myapplication.com/companies/company_name)  
> would be the RESTful way to do it, does that mean using RESTful style  
> routes I cannot achieve the configuration “[www.myapplication.com/](http://www.myapplication.com/)  
> company\_name”?
> 
> Or am I just a rails n00b whos missed the point of RESTful?
> 
> Thanks for any help anyone can give me!

REST means that all the state for specifying the resource is present in  
the URL, instead of in the session or other server state. If  
[www.myapplication.com/company\_name](http://www.myapplication.com/company_name) works for you, that’s fine. It’s a  
perfectly valid RESTful URL. However, the map.resources helper will  
probably have some kind of problem not having a controller name in the  
url, but you can always roll the routes by hand (just specify the  
:method in the :requirements). Just keep in mind this approach could  
also lead to name collisions. Like, if you have a :cookies resource and  
a “cookies” company, those names could collide. Other than that, it  
shouldn’t be a problem.

–  
Josh S.  
[http://blog.hasmanythrough.com](http://blog.hasmanythrough.com)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 5, 2008, 11:19am UTC](https://www.ruby-forum.com/t/restful-routes/123208/3 "2008-02-05T11:19:26Z")

</div>

> > end  
> > I would recommend against using the restful named routes in your  
> > //jarkko
> 
> –  
> Jarkko L.  
> [http://jlaine.net](http://jlaine.net)  
> [http://dotherightthing.com](http://dotherightthing.com)  
> [http://www.railsecommerce.com](http://www.railsecommerce.com)  
> [http://odesign.fi](http://odesign.fi)

Interesting Jarkko…

The restful routes, seem clearer than using urls, maybe not so much  
for this case, but for very long urls, that include for example the  
title of a blog, I would rather use blog\_path(@blog).

Yes, I want to test the full stack, for sure! However, I don’t see how  
using named routes, stops you from doing this…

Webrat two thumbs up, I’ve been using selenium up to now, but would  
like to try other alternatives to see which one works better.

Regards,

Raimond G.

P.S. This message is repeated with the wrong subject somewhere in the  
mailing list, sorry about that ;-|

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 5, 2008, 1:19pm UTC](https://www.ruby-forum.com/t/restful-routes/123208/4 "2008-02-05T13:19:12Z")

</div>

> > NoMethodError: You have a nil object when you didn’t expect it!  
> > Sorry, but I can’t really see anything related to rspec from the  
> > backtrace. I changed to a named route in one of my own steps and it  
> > worked fine. Can you try doing this in a rails integration test and  
> > see if you have a different result?

Will do.

Thanks for the fast replies!

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 5, 2008, 4:20pm UTC](https://www.ruby-forum.com/t/restful-routes/123208/5 "2008-02-05T16:20:00Z")

</div>

On 4.2.2008, at 19.16, Raimond G. wrote:

> like to try other alternatives to see which one works better.  
> What I mean by testing the full stack is that you’d e.g. have this in  
> your story:

clicks\_button “Delete”

If you just use “delete some\_url”, there are two things that could be  
missed:

1. You have forgotten the DELETE method from your delete button.
2. The actual url in the form doesn’t actually point to some\_url.

Neither of the two would be caught unless you used something like  
Webrat to drill through the whole stack. If you’re using blog\_path in  
the story, I feel like you’re using the route to test itself.

Cheers,  
//jarkko

–  
Jarkko L.

> **[jlaine.net](https://jlaine.net/)**
>
> Your freedom to carry a gun messes with my freedom to walk around without fear. Your freedom to “stand your ground” with force is at odds with my …

> **[Home](https://dotherightthing.com/)**
>
> do the right thing

[http://www.railsecommerce.com](http://www.railsecommerce.com)  
[http://odesign.fi](http://odesign.fi)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 5, 2008, 6:38pm UTC](https://www.ruby-forum.com/t/restful-routes/123208/6 "2008-02-05T18:38:59Z")

</div>

> > using named routes, stops you from doing this…  
> > missed:
> 
> –  
> Jarkko L.  
> [http://jlaine.net](http://jlaine.net)  
> [http://dotherightthing.com](http://dotherightthing.com)  
> [http://www.railsecommerce.com](http://www.railsecommerce.com)  
> [http://odesign.fi](http://odesign.fi)

Excellent observations Jarkko!

I’m still trying to get my head around the concept of “testing the  
full stack” and you just enlightened me a little more.

Thanks!

Rai
