Search code examples
ruby-on-railsruby-on-rails-3routesnested-resourcesnested-routes

Nested resource and restricting the Routes Created :only and :except


Good day all,

Can someone kindly assist me with nested resources and its best practice.

I would like to restrict my :events route to only :show and :index, is this the correct way of doing it?

resources :events do
    resources :registrations, :except => [:index]
end

resources :events, :only => [:index, :show]

Is this the best way or the way more Rubyist would handle such thing? I've added two lines of resources :events or is there a way to combine it all in 1 block?

Thanks in advance.


Solution

  • Yes. You can combine it in one block like:

    resources :events, only: [:index, :show] do
        resources :registrations, except: :index
    end