Cannot extend resource routes with path called "new" #2999

Closed
scomma opened this Issue Sep 13, 2011 · 6 comments

Comments

Projects
None yet
3 participants
@scomma

scomma commented Sep 13, 2011

Hi, when I have the following in my routes.rb

resources :contacts do
  post 'new', action: 'new', on: :collection
end

the 'new' path gets stripped away and this route gets created

contacts POST /contacts(.:format) {:action=>"new", :controller=>"contacts"}

If I replace the path 'new' with something else such as 'foo' it registers properly as /contacts/foo.

I've varied the action name and it doesn't seem to matter.

@isaacsanders

This comment has been minimized.

Show comment Hide comment
@isaacsanders

isaacsanders Apr 28, 2012

Contributor

@scomma Is this still an issue? It may be related to the purpose of resources cc/ @steveklabnik

Contributor

isaacsanders commented Apr 28, 2012

@scomma Is this still an issue? It may be related to the purpose of resources cc/ @steveklabnik

@scomma

This comment has been minimized.

Show comment Hide comment
@scomma

scomma Apr 29, 2012

It's still an issue under Rails 3.2.3.

scomma commented Apr 29, 2012

It's still an issue under Rails 3.2.3.

@isaacsanders

This comment has been minimized.

Show comment Hide comment
@isaacsanders

isaacsanders Apr 29, 2012

Contributor

I don't know the specifics, but maybe @spastorino, @tenderlove, or @wycats would be able to help.

Contributor

isaacsanders commented Apr 29, 2012

I don't know the specifics, but maybe @spastorino, @tenderlove, or @wycats would be able to help.

@carlosantoniodasilva

This comment has been minimized.

Show comment Hide comment
@carlosantoniodasilva

carlosantoniodasilva May 4, 2012

Owner

@scomma I see this is a problem because it does not generate the right path, yeah. But, as far as I could see, changing this could probably be a problem when generating the url using the named route, for instance, contacts_path would give you /contacts/new, because it comes first:

     contacts POST   /contacts(.:format)          contacts#new
              GET    /contacts(.:format)          contacts#index
              POST   /contacts(.:format)          contacts#create
  new_contact GET    /contacts/new(.:format)      contacts#new
 edit_contact GET    /contacts/:id/edit(.:format) contacts#edit
      contact GET    /contacts/:id(.:format)      contacts#show
              PUT    /contacts/:id(.:format)      contacts#update
              DELETE /contacts/:id(.:format)      contacts#destroy

So you need to at least give the :as option:

resources :contacts do
  post 'new', action: 'new', on: :collection, as: :new
end
 new_contacts POST   /contacts(.:format)          contacts#new
     contacts GET    /contacts(.:format)          contacts#index

Please note that, a quick fix for this right now is to just enforce the :path as well:

resources :contacts do
  post 'new', action: 'new', on: :collection, as: :new
end
 new_contacts POST   /contacts/new(.:format)      contacts#new
     contacts GET    /contacts(.:format)          contacts#index

I'll verify if this is a possible fix or we should leave it as is. Thanks.

@scomma I see this is a problem because it does not generate the right path, yeah. But, as far as I could see, changing this could probably be a problem when generating the url using the named route, for instance, contacts_path would give you /contacts/new, because it comes first:

     contacts POST   /contacts(.:format)          contacts#new
              GET    /contacts(.:format)          contacts#index
              POST   /contacts(.:format)          contacts#create
  new_contact GET    /contacts/new(.:format)      contacts#new
 edit_contact GET    /contacts/:id/edit(.:format) contacts#edit
      contact GET    /contacts/:id(.:format)      contacts#show
              PUT    /contacts/:id(.:format)      contacts#update
              DELETE /contacts/:id(.:format)      contacts#destroy

So you need to at least give the :as option:

resources :contacts do
  post 'new', action: 'new', on: :collection, as: :new
end
 new_contacts POST   /contacts(.:format)          contacts#new
     contacts GET    /contacts(.:format)          contacts#index

Please note that, a quick fix for this right now is to just enforce the :path as well:

resources :contacts do
  post 'new', action: 'new', on: :collection, as: :new
end
 new_contacts POST   /contacts/new(.:format)      contacts#new
     contacts GET    /contacts(.:format)          contacts#index

I'll verify if this is a possible fix or we should leave it as is. Thanks.

@scomma

This comment has been minimized.

Show comment Hide comment
@scomma

scomma May 4, 2012

You're awesome, thank you :)

scomma commented May 4, 2012

You're awesome, thank you :)

@carlosantoniodasilva

This comment has been minimized.

Show comment Hide comment
@carlosantoniodasilva

carlosantoniodasilva May 4, 2012

Owner

Fixed on master, thanks.

Fixed on master, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment