Rails routing ; concern
concern を使って
resources :user do get :search, on: :collection end resources :article do get :search, on: :collection end
を
concern :searching do get :search, on: :collection end resources :user, concerns: :searching resources :article, concerns: :searching
にできる
Prefix Verb URI Pattern Controller#Action search_users GET /users/search(.:format) users#search users GET /users(.:format) users#index POST /users(.:format) users#create new_user GET /users/new(.:format) users#new edit_user GET /users/:id/edit(.:format) users#edit user GET /users/:id(.:format) users#show PATCH /users/:id(.:format) users#update PUT /users/:id(.:format) users#update DELETE /users/:id(.:format) users#destroy search_articles GET /articles/search(.:format) articles#search articles GET /articles(.:format) articles#index POST /articles(.:format) articles#create new_article GET /articles/new(.:format) articles#new edit_article GET /articles/:id/edit(.:format) articles#edit article GET /articles/:id(.:format) articles#show PATCH /articles/:id(.:format) articles#update PUT /articles/:id(.:format) articles#update DELETE /articles/:id(.:format) articles#destroy