# Why don't these routes work

**URL:** <https://www.ruby-forum.com/t/why-dont-these-routes-work/121975>\
**Category:** Rails\
**Created:** [December 3, 2007, 4:05pm UTC](https://www.ruby-forum.com/t/why-dont-these-routes-work/121975 "2007-12-03T16:05:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rubynuby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ba9def/32.png) [@rubynuby](https://www.ruby-forum.com/u/rubynuby)\
**Post date:** [December 3, 2007, 4:05pm UTC](https://www.ruby-forum.com/t/why-dont-these-routes-work/121975/1 "2007-12-03T16:05:22Z")

</div>

I have this in my routes.db, in its entirety

map.resources :posts, :users  
map.connect ‘’, :controller =\> ‘posts’

map.connect ‘users/:page’,  
:controller =\> ‘users’,  
:action =\> ‘index’,  
:requirements =\> { :page =\> /\d+/}

map.connect ‘users/:id/:page’,  
:requirements =\> { :id =\> /[a-z]+/i, :page =\> /\d+/},  
:controller =\> ‘users’,  
:action =\> ‘show’

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

/users/admin/2 goes to page 2 of the user ‘admin’ as expected. and /  
users go to the users index page.

however, /users/2 shows user with id#2, and not page 2 of the users  
index. I have in my user model

def to\_param  
self.name  
end

and name is never all digits.

seems like it should work. why doesn’t it? thanks.

---

<div class="post-metadata">

**Author:** ![rubynuby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ba9def/32.png) [@rubynuby](https://www.ruby-forum.com/u/rubynuby)\
**Post date:** [December 3, 2007, 5:30pm UTC](https://www.ruby-forum.com/t/why-dont-these-routes-work/121975/2 "2007-12-03T17:30:10Z")

</div>

On 3 Dec 2007, at 15:04, rubynuby wrote:

> /users/admin/2 goes to page 2 of the user ‘admin’ as expected. and /  
> users go to the users index page.
> 
> however, /users/2 shows user with id#2, and not page 2 of the users  
> index. I have in my user model  
> seems like it should work. why doesn’t it? thanks.

Well map.resources :users will add a route mapping users/2 to the user  
with id 2.  
Since it’s higher up in your routes file it will get priority

Fred.

---

<div class="post-metadata">

**Author:** ![rubynuby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ba9def/32.png) [@rubynuby](https://www.ruby-forum.com/u/rubynuby)\
**Post date:** [December 3, 2007, 8:37pm UTC](https://www.ruby-forum.com/t/why-dont-these-routes-work/121975/3 "2007-12-03T20:37:46Z")

</div>

On Dec 3, 8:29 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > map.resources :posts, :users  
> > however, /users/2 shows user with id#2, and not page 2 of the users  
> > index. I have in my user model  
> > seems like it should work. why doesn’t it? thanks.
> 
> Well map.resources :users will add a route mapping users/2 to the user  
> with id 2.  
> Since it’s higher up in your routes file it will get priority
> 
> Fred.

Moving map.resources :users down below didn’t help. in fact, taking  
it out altogether didn’t help. users/2 still shows user with id#2.  
oddly enough, it still understands users/admin. I cleared cache and  
restarted server.

---

<div class="post-metadata">

**Author:** ![rubynuby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ba9def/32.png) [@rubynuby](https://www.ruby-forum.com/u/rubynuby)\
**Post date:** [December 3, 2007, 9:29pm UTC](https://www.ruby-forum.com/t/why-dont-these-routes-work/121975/4 "2007-12-03T21:29:04Z")

</div>

On Dec 3, 11:37 am, rubynuby [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Moving map.resources :users down below didn’t help. in fact, taking  
> it out altogether didn’t help. users/2 still shows user with id#2.  
> oddly enough, it still understands users/admin. I cleared cache and  
> restarted server.

D’OH! I’m an idiot. there’s a map.resources :users right at the top  
which I did not see b/c of all the comments. it’s all good now. for  
those interested, here’s my routes which works well with will\_paginate  
and probably other pagination

# posts is my default controller

map.connect ‘’, :controller =\> ‘posts’

map.connect ‘:page’,  
:action =\> ‘index’,  
:controller =\> ‘posts’,  
:requirements =\> { :page =\> /\d+/},  
:page =\> nil

map.connect ‘:controller/:page’,  
:action =\> ‘index’,  
:requirements =\> { :page =\> /\d+/}

# needs to be adjusted if your ID is all numeric

map.connect ‘:controller/:id/:page’,  
:action =\> ‘show’,  
:requirements =\> { :id =\> /[a-z]+/i, :page =\> /\d+/},  
:page =\> nil

map.connect ‘:controller/:action/:id/:page’,  
:requirements =\> { :page =\> /\d+/},  
:page =\> nil

map.resources :posts, :inkers

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