Some Suggestions on Ruby on Rails routing configuration, rubyrails
When you need to add one or more actions to a RESTful Resource (do you really need it ?), Use member and collection routes.
# Differential get 'subscriptions/: id/unsubscribe 'resources: subscriptions # Good resources: subscriptions do get 'unsubscribe', on: member end # differential get 'photos/search' resources: photos # Good resources: photos do get 'search', on: collection end
If you need to define multiple member/collection routes, use the block syntax alternative ).
Resources: subscriptions do member do get 'unsubscribe' # more routes end resources: photos do collection do get 'search' # more routes end
Use nested routes to better express the relationship with the ActiveRecord model.
class Post < ActiveRecord::Base has_many :comments end class Comments < ActiveRecord::Base belongs_to :post end # routes.rb resources :posts do resources :comments end
Use namespace routing to group related behaviors.
namespace :admin do # Directs /admin/products/* to Admin::ProductsController # (app/controllers/admin/products_controller.rb) resources :products end
Do not use legacy wild controller route in the controller ). This route will allow each controller to access through GET requests.
# Very poor match ': controller (/: action (/: id (.: format )))'