# Restful design is a headache?

**URL:** <https://www.ruby-forum.com/t/restful-design-is-a-headache/165023>\
**Category:** Rails\
**Created:** [April 8, 2009, 11:14am UTC](https://www.ruby-forum.com/t/restful-design-is-a-headache/165023 "2009-04-08T11:14:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![stevedogers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9dc877/32.png) [@stevedogers](https://www.ruby-forum.com/u/stevedogers)\
**Post date:** [April 8, 2009, 11:14am UTC](https://www.ruby-forum.com/t/restful-design-is-a-headache/165023/1 "2009-04-08T11:14:46Z")

</div>

Hi,

So i really, really want to do restful rails. I’ve got the Peepcode  
screencast, read the tutorials, etc.

BUT - I still don’t get it. The problem is, tutorials only cover the  
basic stuff, and none of the application design elements.

For example, I have a shop. The shop has products. The products can only  
be edited by an admin. So I scaffold products, and password protect the  
lot, that’s my admin area done. Now I create a shop and I want to ‘view’  
products. Oh wait, that’s in products already, and that’s not one of the  
‘restful 7’.

I’m completely confused. What about resetting a password? Do I have to  
create a new reset\_password resource?

Any pointer would be much, much appreciated.

Thank you!

---

<div class="post-metadata">

**Author:** ![stevedogers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9dc877/32.png) [@stevedogers](https://www.ruby-forum.com/u/stevedogers)\
**Post date:** [April 8, 2009, 2:23pm UTC](https://www.ruby-forum.com/t/restful-design-is-a-headache/165023/2 "2009-04-08T14:23:09Z")

</div>

view one = show, view many = index, whether its the admin viewing  
products, or a user viewing products, there’s just one HTTP verb and url  
pattern in use…  
/products/ as a GET request.

If it were /products/ as a POST request, it better be accompanied by  
sufficient parameters to define the new product resource, since that’s a  
RESTful create request pattern.

The basis of REST is the four HTTP ‘verbs’ GET, PUT, POST, DELETE.

Rails scaffolding builds REST out with ‘standard’ methods of:

index, show, new, edit, create, update, destroy

which pair a url pattern with one of the four HTTP request types

index:  
/plural\_resource\_name/ + GET - return a collection of the desired  
resource

create:  
/plural\_resource\_name/ + POST - create a new instance of the resource

new:  
/plural\_resource\_name/new + GET - return a new instance of the resource

show:  
/plural\_resource\_name/id + GET - return a single instance of the  
resource

update:  
/plural\_resource\_name/id + PUT - update a single instance of the  
resource

destroy:  
/plural\_resource\_name/id + DELETE - destroy a single instance of the  
resource

---

<div class="post-metadata">

**Author:** ![stevedogers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9dc877/32.png) [@stevedogers](https://www.ruby-forum.com/u/stevedogers)\
**Post date:** [April 8, 2009, 5:06pm UTC](https://www.ruby-forum.com/t/restful-design-is-a-headache/165023/3 "2009-04-08T17:06:09Z")

</div>

I guess there isn’t much information on this, but you might want to  
look at well written source code for inspiration.

From my experience (which isn’t much), your routing table should look  
something like:

map.resources :shops, :has\_many =\> [:products], :shallow =\> true

map.resources :products, :controller =\> “manage\_products”

This means that you will have 3 controllers; one for shops and two for  
products.

One product controller will be used for showing and will be accessed  
as a nested resource of shops. The other will act as a stand alone  
resource, but will be password protected.

This may not be the best design for your needs, but I hope you can  
improve on it.

---

<div class="post-metadata">

**Author:** ![stevedogers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9dc877/32.png) [@stevedogers](https://www.ruby-forum.com/u/stevedogers)\
**Post date:** [April 9, 2009, 12:42am UTC](https://www.ruby-forum.com/t/restful-design-is-a-headache/165023/4 "2009-04-09T00:42:36Z")

</div>

I think the problem may actually be that he’s after application  
architecture tutorials in rails, and most rails tutes take it for  
granted you have somewhat of a grasp on big picture scenarios.

Blog: [http://random8.zenunit.com/](http://random8.zenunit.com/)  
Learn rails: [http://sensei.zenunit.com/](http://sensei.zenunit.com/)

---

<div class="post-metadata">

**Author:** ![stevedogers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9dc877/32.png) [@stevedogers](https://www.ruby-forum.com/u/stevedogers)\
**Post date:** [April 8, 2009, 9:08pm UTC](https://www.ruby-forum.com/t/restful-design-is-a-headache/165023/5 "2009-04-08T21:08:05Z")

</div>

> BUT - I still don’t get it. The problem is, tutorials only cover the  
> basic stuff, and none of the application design elements.

I think a lot of the confusion around REST is that it really is, in  
the practical context of building a rails app anyway, almost too  
simple. That simplicity forces us to rethink how we’ve solved  
problems in the past. And breaking those old thought patterns is what  
is hard.

This presentation really helped me get my mind around it. I’m not  
sure if DHH actually mentions REST in this video but the concepts are  
there.

> **[RailsConf Keynote: David Heinemeier Hansson — ScribeMedia](https://www.scribemedia.org/dhh/)**
>
> We independently review everything we recommend. When you buy through our links, we may earn a commission. Read the full disclosure here. With the release of Rails 1.2, we take a look back at David Heinemeier Hansson’s RailsConf keynote from Chicago....

good luck!
