# Strange Routing

**URL:** <https://www.ruby-forum.com/t/strange-routing/173707>\
**Category:** Rails\
**Created:** [August 13, 2009, 4:43pm UTC](https://www.ruby-forum.com/t/strange-routing/173707 "2009-08-13T16:43:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pmckinstry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f6c823/32.png) [@pmckinstry](https://www.ruby-forum.com/u/pmckinstry)\
**Post date:** [August 13, 2009, 4:43pm UTC](https://www.ruby-forum.com/t/strange-routing/173707/1 "2009-08-13T16:43:47Z")

</div>

Hi Guys,

I have some strangeness with routing, using standard route

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

Using console I did

> > rts = ActionController::Routing::Routes

> > rts.generate(:action =\> “edit”, :controller =\> ‘vendorlocations’, :id =\> 10)  
> > =\> “/vendorlocations/10/edit”
> 
> > rts.recognize\_path("/vendorlocations/10/edit")  
> > =\> {:action=\>“10”, :id=\>“edit”, :controller=\>“vendorlocations”}

1. I don’t understand why the ID is where the action is when I generate  
the router
2. And because of that the :id and :action have been switched.

Has anyone seen this behaviour before? am I doing something wrong?

Many Thanks

Peter

---

<div class="post-metadata">

**Author:** ![pmckinstry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f6c823/32.png) [@pmckinstry](https://www.ruby-forum.com/u/pmckinstry)\
**Post date:** [August 13, 2009, 4:49pm UTC](https://www.ruby-forum.com/t/strange-routing/173707/2 "2009-08-13T16:49:01Z")

</div>

I do have the same question since long…luckily you asked. I’ll watch  
this thread

---

<div class="post-metadata">

**Author:** ![pmckinstry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f6c823/32.png) [@pmckinstry](https://www.ruby-forum.com/u/pmckinstry)\
**Post date:** [August 13, 2009, 5:16pm UTC](https://www.ruby-forum.com/t/strange-routing/173707/3 "2009-08-13T17:16:22Z")

</div>

Rails L. wrote:

> I do have the same question since long…luckily you asked. I’ll watch  
> this thread

I found something which worked - if I did :controller =\>  
‘vendorlocation’ as opposed to :controller =\> ‘vendorlocations’ it  
seemed to do the right thing…

/vendorlocation/edit/:id

Is strange though as when I use the helper

edit\_vendorlocation\_path(location)

It generates the

/vendorlocations/:id/edit which is NOT accepted with a POST but it works  
when in a normal link…

Hmmmmm

---

<div class="post-metadata">

**Author:** ![pmckinstry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f6c823/32.png) [@pmckinstry](https://www.ruby-forum.com/u/pmckinstry)\
**Post date:** [August 13, 2009, 6:21pm UTC](https://www.ruby-forum.com/t/strange-routing/173707/4 "2009-08-13T18:21:16Z")

</div>

if you edit something it should be a GET request and then POST it to  
the update action right? You are better off just removing the default  
routes and rolling your own…

like map.resources :venderlocations

Or is there something I’m missing here…

---

<div class="post-metadata">

**Author:** ![pmckinstry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f6c823/32.png) [@pmckinstry](https://www.ruby-forum.com/u/pmckinstry)\
**Post date:** [August 13, 2009, 6:36pm UTC](https://www.ruby-forum.com/t/strange-routing/173707/5 "2009-08-13T18:36:30Z")

</div>

Hey Pete,

On the latest 2-3-stable I found I had to reverse the last defaults  
connect statements in my routing. They now read:

# Rails default routes

# 

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

That from this change:

> <https://github.com/rails/rails/commit/ff643ce9679ad66a5cd79c90c096496d07d6efaf>

Which is in prep for Rails 3. What version of Rails are you on?

–  
Matthew B. :: 607 227 0871  
Resume & Portfolio @ [http://madhatted.com](http://madhatted.com)

---

<div class="post-metadata">

**Author:** ![pmckinstry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f6c823/32.png) [@pmckinstry](https://www.ruby-forum.com/u/pmckinstry)\
**Post date:** [August 13, 2009, 6:24pm UTC](https://www.ruby-forum.com/t/strange-routing/173707/6 "2009-08-13T18:24:06Z")

</div>

heimdull wrote:

> if you edit something it should be a GET request and then POST it to  
> the update action right? You are better off just removing the default  
> routes and rolling your own…
> 
> like map.resources :venderlocations
> 
> Or is there something I’m missing here…

Its a POST as I am using the remote\_link\_to method which seems to use a  
POST, I’m a total newbie at this so not sure what map.resources does  
(although i will now look it up)

---

<div class="post-metadata">

**Author:** ![pmckinstry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f6c823/32.png) [@pmckinstry](https://www.ruby-forum.com/u/pmckinstry)\
**Post date:** [August 13, 2009, 7:04pm UTC](https://www.ruby-forum.com/t/strange-routing/173707/7 "2009-08-13T19:04:01Z")

</div>

If this is a link\_to\_remote then its a little different. What is it  
that you want to happen when you click the link? If you are new to  
Rails I find it much easier to first get a normal link\_to working then  
start adding ajax to the views.

On Aug 13, 9:24 am, Pete M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
