-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace DashboardManifest with explicit routes #464
Conversation
To be clear, this happened to me on the very first run of the generator. |
Likewise, I just tried installing and it blew up with this error on the first run. Given how painful the magic ends up being in Active Admin, I agree that it's better to just define each admin route like you define your app's routes. The problem with most magic in the routes file is that it basically eager loads the world every time you run a basic command. Rather than using the Rails.application.routes.draw do
namespace :admin do
dashboard_resources :orders
end
end |
@coreyward reading back through your comments, that makes sense. I was able to reproduce it locally as well on my first run. I believe any of the proposed solutions will resolve the first-run issue as well as the issues on subsequent runs. I'm going to take a crack at implementing this in the routes file, and see where that gets us. Stay tuned! |
stub_generator_dependencies | ||
insert_generated_routes | ||
routes_file = file("config/routes.rb") | ||
it "does not invoke the routes generator if namespace routes already exist" do |
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.
Line is too long. [82/80]
Alright, I restructured Administrate to get rid of the |
I definitely like this solution. It keeps the route files cleaner and means one less configuration file. |
Sounds good, merging. |
Problem: Administrate's generated routes have a dependency on the `DashboardManifest`. Often, the generated routes are loaded without `DashboardManfiest` being defined, which throws an error. Solution: Remove the `DashboardManifest` dependency from the generated routes. In order to do this, we will explicitly define the routes in `config/routes.rb`, and remove the `DashboardManifest` entirely. This approach better fits Rails conventions and narrows the public API of Administrate.
f604cd8
to
765d3ff
Compare
Problem:
When users run the
administrate:install
generator multiple times, the generated routes from the first install prevent following installs from working correctly.In order to get subsequent installs to run correctly, users must delete the already-generated routes and run the installer again from scratch.
This has thrown many people off, and there is discussion of the issue in:
Solution:
We should change the generated routes so they don't rely on a
DashboardManifest
being defined.I'm not sure what the best way to do that would be, but here are a couple options
Defining routes directly
This option would look something like:
That would fix the error that people are getting when they run
rails generate administrate:install
multiple times, but it would be more work to update the routes if they change over time.If we went this route, I'd want to look into getting rid of the
DashboardManifest
completely. It would be cumbersome to update the list of dashboards in multiple locations, and we could potentially look at the routes that the user's defined to determine which sidebar links to display.Wrap routes in a conditional
Alternatively we could keep it how it is, but wrap the block in a conditional - that might look like:
Define routes through the engine
This is the approach that RailsAdmin and Active Admin take. It would look like:
This approach is rather opaque, and it makes it harder for the developer to see what's going on. Behind the scenes we could use any approach we wanted to make sure the
DashboardManifest
is defined when we need it.Thoughts?
What's the best approach to take here?
DashboardManifest
altogether, and use the user's routes to fill that role instead?