0

The following scenario:

    resources :first do
        resources :second do
            resources :third do
                resources :fourth do
                    resources :fifth
                end
            end
        end
        resources :third do
            resources :fourth do
                resources :fifth
            end
        end
    end

    resources :second do
        resources :third do
            resources :fourth do
                resources :fifth
            end
        end
    end

    resources :third do
        resources :fourth do
            resources :fifth
        end
    end

    resources :fourth do
        resources :fifth
    end

As you can see, I am using multiple levels of nested resources. The way I set this up feels pretty repetitive though.

Is there a way to make this more clean?

2
  • 1
    I don't know what you're trying to accomplish, but I would highly advise you to reconsider your routing scheme. Having 5 levels of nested resources will become extremely cumbersome. I would have a look at Jamis Buck's short paper discussing nested resources. Commented Mar 4, 2017 at 22:05
  • @Mark You are right. I just wanted to know if there is a way to prevent duplication in routes theoretically. I am not planning to nest resources four or five levels :) Commented Mar 4, 2017 at 23:37

1 Answer 1

2

You can use routing concerns to avoid duplication in your routes, e.g.:

concern: :my_concern
  resources :fourth do
    resources :fifth
  end
end

resources :third, concerns: :my_concern
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.