[Ruby on Rails] How to limit default actions with 'only' while adding custom actions

Tadashi Shigeoka ·  Thu, December 20, 2012

A memo on how to limit default actions with ‘only’ while adding custom actions in Ruby on Rails routing configuration.

resources :blogs, only: %w[index show] do
  collection do
    get 'search'
  end
end

When you run rake routes, you should see blogs#search added in addition to blogs#index and blogs#show.

That’s all from the Gemba.