# Rails 2.0 vs. custom routes

**URL:** <https://www.ruby-forum.com/t/rails-2-0-vs-custom-routes/124213>\
**Category:** Rails\
**Created:** [December 26, 2007, 3:52pm UTC](https://www.ruby-forum.com/t/rails-2-0-vs-custom-routes/124213 "2007-12-26T15:52:39Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![sharkie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58f4c7/32.png) [@sharkie](https://www.ruby-forum.com/u/sharkie)\
**Post date:** [December 26, 2007, 3:52pm UTC](https://www.ruby-forum.com/t/rails-2-0-vs-custom-routes/124213/1 "2007-12-26T15:52:39Z")

</div>

In previous Rails, I used to use these (for example)

/users/1  
/users;expand\_all  
/users/1;say\_hello

Now in Rails 2.0, I believe I am supposed to use these

/users/1  
/users/expand\_all  
/users/1/say\_hello

Am I correct?

But somehow, when I try /users/expand\_all, accessing action show with  
:id =\> “expand\_all” rather than accessing action expand\_all

Is there something in my routes.rb that must be reconfigured?

---

<div class="post-metadata">

**Author:** ![sharkie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58f4c7/32.png) [@sharkie](https://www.ruby-forum.com/u/sharkie)\
**Post date:** [December 26, 2007, 4:19pm UTC](https://www.ruby-forum.com/t/rails-2-0-vs-custom-routes/124213/2 "2007-12-26T16:19:47Z")

</div>

Check out the new ‘rake routes’ command. It’ll show you what available  
routes and helpers you have. Also, check out this sweet cheatsheet:

> **[REST-cheatsheet.pdf](https://topfunky.com/clients/peepcode/REST-cheatsheet.pdf)**
>
> 78.73 KB

Your route should look something like this:  
map.resources :users, :collection =\> { :expand\_all =\> :get }

And, from your view, you should be doing something like this (assuming  
you’ve defined “expand\_all” as a collection route as opposed to a  
singular route):

\<%= link\_to ''Expand All Users", expand\_all\_users\_path %\>

If you’ve defined your “expand\_all” route as singular, then I’d expect  
to see behavior similar to what you’re seeing. If you can’t get it  
working, post your routes.rb file here.

On Dec 26, 9:52 am, Sharkie L. \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![sharkie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58f4c7/32.png) [@sharkie](https://www.ruby-forum.com/u/sharkie)\
**Post date:** [December 26, 2007, 4:47pm UTC](https://www.ruby-forum.com/t/rails-2-0-vs-custom-routes/124213/3 "2007-12-26T16:47:31Z")

</div>

I looked at the cheatsheet. In fact it refers to previous versions of  
Rails, and not Rails 2.0.

---

<div class="post-metadata">

**Author:** ![sharkie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58f4c7/32.png) [@sharkie](https://www.ruby-forum.com/u/sharkie)\
**Post date:** [December 26, 2007, 4:45pm UTC](https://www.ruby-forum.com/t/rails-2-0-vs-custom-routes/124213/4 "2007-12-26T16:45:49Z")

</div>

map.resources :users,  
:collection =\> {  
:expand\_all =\> :get  
}

map.resources :users,  
:member =\> {  
:say\_hello =\> :get  
}

# Install the default route as the lowest priority.

map.connect ‘:controller/:action/:id’

However when I call /users/expand all, it routes to :controller =\>  
users\_controller, :action =\> show, :id =\> “expand\_all” which is wrong.

rake routes on the other hand reports the correct routing.

---

<div class="post-metadata">

**Author:** ![sharkie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58f4c7/32.png) [@sharkie](https://www.ruby-forum.com/u/sharkie)\
**Post date:** [December 26, 2007, 5:05pm UTC](https://www.ruby-forum.com/t/rails-2-0-vs-custom-routes/124213/5 "2007-12-26T17:05:15Z")

</div>

I just tried it. Same problem still ☹

---

<div class="post-metadata">

**Author:** ![sharkie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58f4c7/32.png) [@sharkie](https://www.ruby-forum.com/u/sharkie)\
**Post date:** [December 26, 2007, 4:57pm UTC](https://www.ruby-forum.com/t/rails-2-0-vs-custom-routes/124213/6 "2007-12-26T16:57:51Z")

</div>

Ah, there’s the problem.

Try this:

map.resources :users,  
:collection =\> {  
:expand\_all =\> :get  
},  
:member =\> {  
:say\_hello =\> :get  
}

By calling map.resources twice, you’re overriding the first one. You  
have to map each resource as a single call.

On Dec 26, 10:45 am, Sharkie L. \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![sharkie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58f4c7/32.png) [@sharkie](https://www.ruby-forum.com/u/sharkie)\
**Post date:** [December 26, 2007, 5:06pm UTC](https://www.ruby-forum.com/t/rails-2-0-vs-custom-routes/124213/7 "2007-12-26T17:06:09Z")

</div>

Got it to work now. Thanks!

---

<div class="post-metadata">

**Author:** ![sharkie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58f4c7/32.png) [@sharkie](https://www.ruby-forum.com/u/sharkie)\
**Post date:** [December 26, 2007, 5:35pm UTC](https://www.ruby-forum.com/t/rails-2-0-vs-custom-routes/124213/8 "2007-12-26T17:35:56Z")

</div>

I find the RESTful routing very confusing for anything other than the  
CRUD mode. I can see how GET/PUT/POST/DELETE maps to the controller for  
that. Its been soooooo well documented and soooooo many examples; I’m  
almost sick of it.

But many of us aren’t doing the kind of model that is in AWDWR, the  
catalogue/invoice type of thing.

There’s a whole class of applications that have a very different front  
end" Wikis, Games and so forth. Essentially they have one UI because  
there is only the one conceptual model that that the user sees. (The  
AWDWR has a catalogue view, a invoice view …).

Something like Instiki has 26 public methods - that is things that can  
appear as URLs in buttons. Not all of them fit very obviously into the  
GPPD approach.

I can squint hard and treat the various print and RSS/Atom as special  
cases of ‘view’, all I’ve really done, as far as I can see, is made my  
menu button code more complicated.

Instiki also has one shortcoming that is easy to get around. Its urls  
are of the form  
[somedomain.com](http://www.somedomain.com/wiki/) …  
to point to the wiki controller.  
For many domains this is unacceptable. Yes, I know it can be cleaned up  
with Apache mod\_rewrite, but many of us use hosted services and would  
rather do it with the application - in routes.

So would those Rails-ists experienced in resourceful techniques please  
help out the rest of us and come up with examples and illustrations that  
are a little different, that aren’t in the CRUD model, that don’t  
require the name of the controller in the URL to do a 1:1 mapping  
url:controller.

Please, lets see some flexibility rather than the same old same old  
being repeated. Those who do want the CRUD mode - well there’s plenty  
out there on the 'Net right now, you don’t need to add to it with “me  
too” postings.

–  
Over the last few centuries, mathematicians have demonstrated  
a remarkable tendency to underestimate the cryptanalytic powers  
of blunt and heavy objects.  
– Jamie Reid, CISSP

---

<div class="post-metadata">

**Author:** ![sharkie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58f4c7/32.png) [@sharkie](https://www.ruby-forum.com/u/sharkie)\
**Post date:** [December 26, 2007, 6:12pm UTC](https://www.ruby-forum.com/t/rails-2-0-vs-custom-routes/124213/9 "2007-12-26T18:12:50Z")

</div>

Btw, everything in that cheatsheet applies to Rails 2.0.

On Dec 26, 10:47 am, Sharkie L. \<rails-mailing-l…@andreas-
