codidact / qpixel

Q&A-based community knowledge-sharing software
https://codidact.com
GNU Affero General Public License v3.0
385 stars 69 forks source link

Improve rails console experience #1172

Closed Taeir closed 1 year ago

Taeir commented 1 year ago

This PR improves the user experience of using the rails console (rails c).

Normally, to use the rails console, one would need to set the RequestContext.community to be able to run most commands. With the changes in this PR, the console will automatically set a community if it can, and will provide some instructions on how to create one / switch communities if there are 0 or multiple.

IRB profile

Additionally, this defines an IRB profile that can be added in your ~/.irbrc as follows:

Qpixel.irb! if defined?(Qpixel)

It will change the prompt to show the current rails environment and current community

image

.

image

. It will update automatically when you switch community:

image

Overview

In full, these changes look like the following:

example of console with new prompt mode

.

image

If no communities are found, the following is displayed in development:

Example of initialization in development mode when no communities are present

If no communities are found, the following is displayed in In production:

Example of initialization in production mode when no communities are present

If an error occurs (usually related to missing database settings):

Example of initalization with incorrect database settings