0

I am looking for a better solution than what I currently have for my routes. They are deeply nested and there has to be a better solution for what I have done (thus far).

This is what I have so far:

  namespace "api" do
    namespace "v1" do
      resources :countries do
        resources :states do 
          resources :counties do
            resource :districts do
              resource :schools
            end
          end
        end
      end
    end
  end

I am quickly running into issues where going directly to a district (for example) means I need to create a separate district resource outside of the nested resources already there. Obviously I am doing this wrong (it just doesn't feel right)... anyone know what I can do to better my routing experience?

Refactored Code:

  namespace "api" do
    namespace "v1" do

      resources :countries do
        resources :states
      end

      resources :states do
        resources :counties
      end

      resources :counties do
        resources :districts
      end

      resources :districts do
        resources :schools
      end

    end # end v1 Namespace
  end # end api Namespace
dennismonsewicz
  • 25,132
  • 33
  • 116
  • 189

0 Answers0