Search code examples
ruby-on-railsruby-on-rails-5rails-routing

How to pass a symbol through rails routes specified through 'resources'?


I have this set of routes

  resources :flatfiles do
    collection do
      delete :custom_destroy
    end
  end

And I would like to all of the routes to include :key

E.g. get 'flatfiles/:key' => 'flatfiles#index'

I could specify each route individually (like the get action above), but is there a way to do them all at once?


Solution

  • You can use :path

      resources :flatfiles, path: 'flatfiles/:key' do
        collection do
          delete :custom_destroy
        end
      end
    

    That will prefix all sub routes with :key