Skip to main content
added 261 characters in body
Source Link
user229044
  • 853
  • 5
  • 15

Yes, use namespace and resources:

namespace :oauth do
  resources :apps, controller: "applications", as: :applications
end

This is not 100% identical (the names of some of your routes have changed) but it is the way you should be building your routes, and you should change the rest of your app to reflect the change.

The primary difference is your names for the create and destroy routes have gone away; these routes shouldn't have names anyways. When you want to create/destroy a model, you should be using oath_applications_path, with method: :post or method: :delete, not oath_apps_new_path/destroy_oauth_application_path.

My way also uses the correct verb (PUT) for updates.

Your rake routes:

       oauth_applications GET    /oauth/apps(.:format)             oauth/applications#index
    new_oauth_application GET    /oauth/apps/new(.:format)         oauth/applications#new
           oauth_apps_new POST   /oauth/apps/new(.:format)         oauth/applications#create
        oauth_application GET    /oauth/apps/:id(.:format)         oauth/applications#show
   edit_oauth_application GET    /oauth/apps/:id/edit(.:format)    oauth/applications#edit
                          POST   /oauth/apps/:id/edit(.:format)    oauth/applications#update
destroy_oauth_application DELETE /oauth/apps/:id/destroy(.:format) oauth/applications#destroy

My rake routes (reordered to match yours):

    oauth_applications GET    /oauth/apps(.:format)          oauth/applications#index
 new_oauth_application GET    /oauth/apps/new(.:format)      oauth/applications#new
                       POST   /oauth/apps(.:format)          oauth/applications#create
edit_oauth_application     oauth_application GET    /oauth/apps/:id/edit(.:format) oauth/applications#edit
     oauth_applicationoauth/applications#show
edit_oauth_application GET    /oauth/apps/:id/edit(.:format)      oauth/applications#showapplications#edit
                       PUT    /oauth/apps/:id(.:format)      oauth/applications#update
                       DELETE /oauth/apps/:id(.:format)      oauth/applications#destroy

Yes, use namespace and resources:

namespace :oauth do
  resources :apps, controller: "applications", as: :applications
end

This is not 100% identical (the names of some of your routes have changed) but it is the way you should be building your routes, and you should change the rest of your app to reflect the change.

Your rake routes:

       oauth_applications GET    /oauth/apps(.:format)             oauth/applications#index
    new_oauth_application GET    /oauth/apps/new(.:format)         oauth/applications#new
           oauth_apps_new POST   /oauth/apps/new(.:format)         oauth/applications#create
        oauth_application GET    /oauth/apps/:id(.:format)         oauth/applications#show
   edit_oauth_application GET    /oauth/apps/:id/edit(.:format)    oauth/applications#edit
                          POST   /oauth/apps/:id/edit(.:format)    oauth/applications#update
destroy_oauth_application DELETE /oauth/apps/:id/destroy(.:format) oauth/applications#destroy

My rake routes:

    oauth_applications GET    /oauth/apps(.:format)          oauth/applications#index
 new_oauth_application GET    /oauth/apps/new(.:format)      oauth/applications#new
                       POST   /oauth/apps(.:format)          oauth/applications#create
edit_oauth_application GET    /oauth/apps/:id/edit(.:format) oauth/applications#edit
     oauth_application GET    /oauth/apps/:id(.:format)      oauth/applications#show
                       PUT    /oauth/apps/:id(.:format)      oauth/applications#update
                       DELETE /oauth/apps/:id(.:format)      oauth/applications#destroy

Yes, use namespace and resources:

namespace :oauth do
  resources :apps, controller: "applications", as: :applications
end

This is not 100% identical (the names of some of your routes have changed) but it is the way you should be building your routes, and you should change the rest of your app to reflect the change.

The primary difference is your names for the create and destroy routes have gone away; these routes shouldn't have names anyways. When you want to create/destroy a model, you should be using oath_applications_path, with method: :post or method: :delete, not oath_apps_new_path/destroy_oauth_application_path.

My way also uses the correct verb (PUT) for updates.

Your rake routes:

       oauth_applications GET    /oauth/apps(.:format)             oauth/applications#index
    new_oauth_application GET    /oauth/apps/new(.:format)         oauth/applications#new
           oauth_apps_new POST   /oauth/apps/new(.:format)         oauth/applications#create
        oauth_application GET    /oauth/apps/:id(.:format)         oauth/applications#show
   edit_oauth_application GET    /oauth/apps/:id/edit(.:format)    oauth/applications#edit
                          POST   /oauth/apps/:id/edit(.:format)    oauth/applications#update
destroy_oauth_application DELETE /oauth/apps/:id/destroy(.:format) oauth/applications#destroy

My rake routes (reordered to match yours):

    oauth_applications GET    /oauth/apps(.:format)          oauth/applications#index
 new_oauth_application GET    /oauth/apps/new(.:format)      oauth/applications#new
                       POST   /oauth/apps(.:format)          oauth/applications#create
     oauth_application GET    /oauth/apps/:id(.:format)      oauth/applications#show
edit_oauth_application GET    /oauth/apps/:id/edit(.:format) oauth/applications#edit
                       PUT    /oauth/apps/:id(.:format)      oauth/applications#update
                       DELETE /oauth/apps/:id(.:format)      oauth/applications#destroy
Source Link
user229044
  • 853
  • 5
  • 15

Yes, use namespace and resources:

namespace :oauth do
  resources :apps, controller: "applications", as: :applications
end

This is not 100% identical (the names of some of your routes have changed) but it is the way you should be building your routes, and you should change the rest of your app to reflect the change.

Your rake routes:

       oauth_applications GET    /oauth/apps(.:format)             oauth/applications#index
    new_oauth_application GET    /oauth/apps/new(.:format)         oauth/applications#new
           oauth_apps_new POST   /oauth/apps/new(.:format)         oauth/applications#create
        oauth_application GET    /oauth/apps/:id(.:format)         oauth/applications#show
   edit_oauth_application GET    /oauth/apps/:id/edit(.:format)    oauth/applications#edit
                          POST   /oauth/apps/:id/edit(.:format)    oauth/applications#update
destroy_oauth_application DELETE /oauth/apps/:id/destroy(.:format) oauth/applications#destroy

My rake routes:

    oauth_applications GET    /oauth/apps(.:format)          oauth/applications#index
 new_oauth_application GET    /oauth/apps/new(.:format)      oauth/applications#new
                       POST   /oauth/apps(.:format)          oauth/applications#create
edit_oauth_application GET    /oauth/apps/:id/edit(.:format) oauth/applications#edit
     oauth_application GET    /oauth/apps/:id(.:format)      oauth/applications#show
                       PUT    /oauth/apps/:id(.:format)      oauth/applications#update
                       DELETE /oauth/apps/:id(.:format)      oauth/applications#destroy