-
-
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
Adding an error message during 'administrate' initialize when there are no models in db. #1782
Adding an error message during 'administrate' initialize when there are no models in db. #1782
Conversation
@@ -10,6 +10,12 @@ class InstallGenerator < Rails::Generators::Base | |||
|
|||
class_option :namespace, type: :string, default: "admin" | |||
|
|||
def model_check | |||
if database_models.none? | |||
puts "ERROR: Unable to generate a dashboard without models." |
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.
What do you think about phrasing it something like: "Add models before installing Administrate" or similar?
I'm thinking that we want to just say that you can't have Administrate at all without models, which is broadly true and covers the cases where someone is trying to install Administrate before creating the first model which is a common first-use error.
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.
I think that is a better phrase, also as the check doesn't stop the rest of the generator trying to run (which could be done) maybe adding blank lines above and below to make it standout?
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.
We could exit
after the error. Is there anything in Rails' existing generators which behaves in a similar way?
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.
I was initially wondering if we should actually be writing to standard error, but a quick search around didn't seem to find that being used for generators (but I might've just looked in bad places.)
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.
I can't find any other example of a generator exiting... so exit
could be the best solution.
I think a puts error would be fine, especially if its the last output on the CL
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.
Yeah, sounds good!
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 looks almost ready now. Just two things:
- The tests are failing because of a security advisory on a dependency. They should pass if you rebase.
- Make sure to correct the linter warnings raised by Hound.
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.
LGTM 👍
Co-authored-by: Rachael Ewins <[email protected]>
Thank you! |
This PR fixes the behaviour observed, during the administrate install on rails apps without models, where the admin route isn't created, resulting in an application error and no warning to the user.
The change displays a friendly error message, when this happens.