Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Closed
scomma opened this Issue · 6 comments

3 participants

@scomma

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

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

@scomma

It's still an issue under Rails 3.2.3.

@isaacsanders

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

@carlosantoniodasilva

@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.

@carlosantoniodasilva carlosantoniodasilva referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@scomma

You're awesome, thank you :)

@carlosantoniodasilva carlosantoniodasilva referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@carlosantoniodasilva carlosantoniodasilva closed this issue from a commit
@carlosantoniodasilva carlosantoniodasilva Force given path to http methods in mapper to skip canonical action c…
…hecking

This fixes the following scenario:

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

Where the /new path is not generated because it's considered a canonical
action, part of the normal resource actions:

    new_contacts POST   /contacts(.:format)          contacts#new

Fixes #2999
d03aa10
@carlosantoniodasilva

Fixed on master, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.