-
-
Notifications
You must be signed in to change notification settings - Fork 270
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Fix issue with loading dynamic routes #3369
Fix issue with loading dynamic routes #3369
Conversation
Per the Rails guides, you should not call `Avo::Engine.routes.draw` again when loading routes from another file. See https://guides.rubyonrails.org/routing.html#breaking-up-very-large-route-file-into-multiple-small-ones for details.
Code Climate has analyzed commit 41ee230 and detected 0 issues on this pull request. View more on Code Climate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach isn't generating the routes as expected.
In my opinion, Avo::DynamicRouter
no longer needs this level of abstraction. Previously, it had more code, making the extraction useful, but now it’s compact enough to apply directly in config/routes.rb
instead of a separate file.
Let's remove the lib/avo/dynamic_router.rb
and directly apply the code where Avo::DynamicRouter.routes
was called.
Replace
# Generate resource routes as below:
# resources :posts
Avo::DynamicRouter.routes
With
# Generate resource routes as below:
# resources :posts
Avo::Resources::ResourceManager.fetch_resources.map do |resource|
resources resource.route_key do
member do
get :preview
end
end
end
P.S. I just noticed you suggested this in the description as well. At this point, the change makes sense. It didn’t when Avo::DynamicRouter
was more complex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @davidlormor for this contribution!
🙌 no problem @Paul-Bob - happy to help get that cleaned up! Especially now that I've realized my challenges with ID constraints (#3368) are a bit more broad than I'd originally realized. Turns out the proprietary data set that I'm working with has several tables with composite keys in addition to some of the other ID formats already mentioned. I also realized that all of the workarounds ( I'm taking some time to work through the whole data set so I can have a better grasp of the scope of the issue, and which parts are Avo-related vs. Rails-related. |
Thanks Paul for pushing this over the finish line and thanks David for helping us deal with our dirty laundry 🙌 |
Description
Per the [Rails guides](https://guides.rubyonrails.org/routing.html#breaking-up-very-large-route-file-into-multiple-small-ones for details), you should not call
Avo::Engine.routes.draw
again when loading routes from another file.This is related to #3368. Doesn't actually fix the issue, but this change is required in order to ensure that an
:id
constraint can be applied to all resource-related routes.Based on the Rails guides, I would suggest the following change, but didn't want to do anything too drastic:
If you want to take it even a step further, the Rails guides suggests only breaking up your routes file when it goes extremely large and complex, so an even simpler version would be:
Either method would ensure that any potential fix to #3368 would be able to properly apply a routing constraint to all resource routes.
Checklist:
Screenshots & recording
Manual review steps