# Restfully Noob

**URL:** <https://www.ruby-forum.com/t/restfully-noob/81343>\
**Category:** Rails\
**Created:** [January 8, 2007, 3:26am UTC](https://www.ruby-forum.com/t/restfully-noob/81343 "2007-01-08T03:26:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pezdude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@pezdude](https://www.ruby-forum.com/u/pezdude)\
**Post date:** [January 8, 2007, 3:26am UTC](https://www.ruby-forum.com/t/restfully-noob/81343/1 "2007-01-08T03:26:44Z")

</div>

I’ve been playing with REST today and can’t quite figure out a routing  
issue.

I have a controller named Accounts which has 3 actions:  
1. new  
2. create  
3. chuck

My routes file has the following:

```
 map.resources :accounts, :member => { :chuck => :get }
 map.connect ':controller/:action/:id'

```

These are the urls I would expect to work, but they both produce errors:

```
http://localhost:3000/accounts/;chuck
Produces: Routing Error: no route found
          to match "/accounts/;chuck" with {:method=>:get}
    or
http://localhost:3000/accounts/chuck
Produces: Unknown action: no action responded to show

```

This actually works, but

```
http://localhost:3000/accounts/1;chuck
but doesn't really contain a valid id, can put anything where the 1

```

is.

Just wondering what I am doing wrong?

Thanks,

Dave

---

<div class="post-metadata">

**Author:** ![pezdude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@pezdude](https://www.ruby-forum.com/u/pezdude)\
**Post date:** [January 8, 2007, 5:34am UTC](https://www.ruby-forum.com/t/restfully-noob/81343/2 "2007-01-08T05:34:46Z")

</div>

Hi David,

The last route is correct, but what is the chuck method doing ?

maybe you’re looking for :collection =\> {:chuck =\> :get}

---

<div class="post-metadata">

**Author:** ![pezdude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@pezdude](https://www.ruby-forum.com/u/pezdude)\
**Post date:** [January 8, 2007, 3:46pm UTC](https://www.ruby-forum.com/t/restfully-noob/81343/3 "2007-01-08T15:46:27Z")

</div>

isaac wrote:

> Hi David,
> 
> The last route is correct, but what is the chuck method doing ?
> 
> maybe you’re looking for :collection =\> {:chuck =\> :get}

Hi Isaac,

Chuck really doesn’t do anything, I was just messing with trying to add  
a non-standard REST action to a controller.

The thing that’s weird is:

[http://localhost:3000/accounts/1;chuck](http://localhost:3000/accounts/1;chuck)  
[http://localhost:3000/accounts/beetlejuice;chuck](http://localhost:3000/accounts/beetlejuice;chuck)  
[http://localhost:3000/accounts/anythingthatdoesntmatter;chuck](http://localhost:3000/accounts/anythingthatdoesntmatter;chuck)

all work.

I want the chuck action to function like a nonREST action. The action  
requires no id, yet since it’s a get, it requires an id.

In other words, I’d like the “chuck” action to function like the “index”  
action, since “index” requires no id.

Hope that makes sense.

Thanks!

---

<div class="post-metadata">

**Author:** ![pezdude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@pezdude](https://www.ruby-forum.com/u/pezdude)\
**Post date:** [January 9, 2007, 3:44pm UTC](https://www.ruby-forum.com/t/restfully-noob/81343/4 "2007-01-09T15:44:09Z")

</div>

isaac wrote:

Hi Isaac,

Just trying to see what’s possible with map.resources. I got the new  
agile 1.2 book - but it really doesn’t explain the difference between a  
collection and a member very well.

Thanks again.

Dave

---

<div class="post-metadata">

**Author:** ![pezdude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@pezdude](https://www.ruby-forum.com/u/pezdude)\
**Post date:** [January 9, 2007, 8:16pm UTC](https://www.ruby-forum.com/t/restfully-noob/81343/5 "2007-01-09T20:16:29Z")

</div>

Hi Dave,

> Just trying to see what’s possible with map.resources. I got  
> the new agile 1.2 book - but it really doesn’t explain the difference  
> between a collection and a member very well.

In a Rails way, it would be Collection has\_many :members,  
Member belongs\_to :collection 🙂

```
  -- Jean-FranÃ§ois.

```

–  
Ã€ la renverse.

---

<div class="post-metadata">

**Author:** ![pezdude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@pezdude](https://www.ruby-forum.com/u/pezdude)\
**Post date:** [January 19, 2007, 4:31pm UTC](https://www.ruby-forum.com/t/restfully-noob/81343/6 "2007-01-19T16:31:19Z")

</div>

In this context a member would mean an individual instance of the model  
Account.

A collection would be interested in more than one member of the model  
Account.

So the index route/action/view is a collection because it is accessing  
a collection of accounts (possibly all accounts)

The show route/action/view however is a member because it is only  
interested in one member of the model Account. (hence :id being part  
of the route - this is how the individual member is identified)

I hope this is helpful and not more confusing 🙂

disclaimer: I am quite new to ruby/rails/REST so please don’t take my  
word as gospel.

---

<div class="post-metadata">

**Author:** ![pezdude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@pezdude](https://www.ruby-forum.com/u/pezdude)\
**Post date:** [January 9, 2007, 11:34am UTC](https://www.ruby-forum.com/t/restfully-noob/81343/7 "2007-01-09T11:34:58Z")

</div>

Its not really that weird is it ?

In the second case its passing beetlejuice as the id, your controller  
doesn’t know its an invalid id until you try and find the record -  
@account = Account.find(params[:id])

I think you have 2 choices here:

1. You can keep everything RESTful and add chuck in like this:

map.resources :accounts, :collection =\> {:chuck =\> :get}

which will give you the route /accounts;chuck

1. you can include a custom route before your map.resources like this:

map.connect ‘accounts/chuck’, :controller =\> ‘accounts’, :action =\>  
‘chuck’

which give you the route /accounts/chuck

Your choice…#2 is not the restful way AFAIK
