Why does the helper path for POST change when index is removed from routes?

Viewed 49

Normally such a line in routes.rb

resources :tenants

generates the following routes (and a few more):

| tenants_path | GET  | /tenants(.:format) | tenants#index |
|              | POST | /tenants(.:format) | tenants#create |

However when I try to remove index action from routes.rb like this:

resources :tenants, except: :index

The Path/Url helper for tenants#create POST action is overridden and is given the tenants_path:

| tenants_path | POST | /tenants(.:format) | tenants#create |

Why does it happen and how can it be avoided?

2 Answers

The path helper name is only shown for the first matching route in the generated rails routes. tenants_path will generate example.com/tenants. What REST method to use, e.g. GET, POST or something else Rails figures out on its own.

| tenants_path | GET |
|              | POST |

When you say except: :index is just means the first matching route is different, the generated path is still example.com/tenants

| tenants_path | POST |
Related