3
\$\begingroup\$

I'm hoping someone could vet my route structure as I've really been struggling with getting something that feels right. Right now I have this nested resource structure:

Rails.application.routes.draw do
  concern :configable do
    resource :config, only: %i[edit update]
  end

  resources :tags do
    scope module: 'tags' do
      resources :versions,
                concerns: :configable,
                shallow: true,
                shallow_path: 'tags',
                shallow_prefix: 'tag' do
        scope module: 'versions' do
          resources :files,
                    shallow: true,
                    shallow_path: 'versions',
                    shallow_prefix: 'version'
          resources :snippets,
                    shallow: true,
                    shallow_path: 'versions',
                    shallow_prefix: 'version'
        end
      end
    end
  end
end

Result:

                   Prefix Verb   URI Pattern                                                                              Controller#Action
        tag_version_files GET    /tags/versions/:version_id/files(.:format)                                               tags/versions/files#index
                          POST   /tags/versions/:version_id/files(.:format)                                               tags/versions/files#create
     new_tag_version_file GET    /tags/versions/:version_id/files/new(.:format)                                           tags/versions/files#new
    edit_tag_version_file GET    /tags/versions/files/:id/edit(.:format)                                                  tags/versions/files#edit
         tag_version_file GET    /tags/versions/files/:id(.:format)                                                       tags/versions/files#show
                          PATCH  /tags/versions/files/:id(.:format)                                                       tags/versions/files#update
                          PUT    /tags/versions/files/:id(.:format)                                                       tags/versions/files#update
                          DELETE /tags/versions/files/:id(.:format)                                                       tags/versions/files#destroy
     tag_version_snippets GET    /tags/versions/:version_id/snippets(.:format)                                            tags/versions/snippets#index
                          POST   /tags/versions/:version_id/snippets(.:format)                                            tags/versions/snippets#create
  new_tag_version_snippet GET    /tags/versions/:version_id/snippets/new(.:format)                                        tags/versions/snippets#new
 edit_tag_version_snippet GET    /tags/versions/snippets/:id/edit(.:format)                                               tags/versions/snippets#edit
      tag_version_snippet GET    /tags/versions/snippets/:id(.:format)                                                    tags/versions/snippets#show
                          PATCH  /tags/versions/snippets/:id(.:format)                                                    tags/versions/snippets#update
                          PUT    /tags/versions/snippets/:id(.:format)                                                    tags/versions/snippets#update
                          DELETE /tags/versions/snippets/:id(.:format)                                                    tags/versions/snippets#destroy
  edit_tag_version_config GET    /tags/versions/:version_id/config/edit(.:format)                                         tags/configs#edit
       tag_version_config PATCH  /tags/versions/:version_id/config(.:format)                                              tags/configs#update
                          PUT    /tags/versions/:version_id/config(.:format)                                              tags/configs#update
             tag_versions GET    /tags/:tag_id/versions(.:format)                                                         tags/versions#index
                          POST   /tags/:tag_id/versions(.:format)                                                         tags/versions#create
          new_tag_version GET    /tags/:tag_id/versions/new(.:format)                                                     tags/versions#new
         edit_tag_version GET    /tags/versions/:id/edit(.:format)                                                        tags/versions#edit
              tag_version GET    /tags/versions/:id(.:format)                                                             tags/versions#show
                          PATCH  /tags/versions/:id(.:format)                                                             tags/versions#update
                          PUT    /tags/versions/:id(.:format)                                                             tags/versions#update
                          DELETE /tags/versions/:id(.:format)                                                             tags/versions#destroy
                     tags GET    /tags(.:format)                                                                          tags#index
                          POST   /tags(.:format)                                                                          tags#create
                  new_tag GET    /tags/new(.:format)                                                                      tags#new
                 edit_tag GET    /tags/:id/edit(.:format)                                                                 tags#edit
                      tag GET    /tags/:id(.:format)                                                                      tags#show
                          PATCH  /tags/:id(.:format)                                                                      tags#update
                          PUT    /tags/:id(.:format)                                                                      tags#update
                          DELETE /tags/:id(.:format)                                                                      tags#destroy

I'm wondering if A) there's a more succinct way to get that structure with a combinations of namespace/scope and B) if perhaps that structure is not the best way to go about it. I like it because it keeps the directory structure clean but am very open to cleaning it up. Not sure if having resources under a path prefix (in the case of versions) qualifies as breaking the more-than-one-nested-resource deep advice I've gotten from many people.

\$\endgroup\$

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.