Strange Routing

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

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

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

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…

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:

http://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

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)

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. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs