diff --git a/README.md b/README.md index 19bbc58..41dcdd9 100644 --- a/README.md +++ b/README.md @@ -6,14 +6,15 @@ Why another Ruby on Rails admin? We wanted an admin that was: -* Familiar and customizable like Rails scaffolds (less DSL) -* Supports all the Rails features out of the box (ActionText, ActionMailbox, has_secure_password, etc) -* Stimulus / Turbolinks / Hotwire ready +- Familiar and customizable like Rails scaffolds (less DSL) +- Supports all the Rails features out of the box (ActionText, ActionMailbox, has_secure_password, etc) +- Stimulus / Turbolinks / Hotwire ready ![Madmin Screenshot](docs/images/screenshot.png) _We're still working on the design!_ ## Installation + Add `madmin` to your application's Gemfile: ```bash @@ -40,6 +41,23 @@ To generate a resource for a model, you can run: rails g madmin:resource ActionText::RichText ``` +### Avoid N+1 queries + +In case of N+1 queries, you can preload the association by overriding the `scoped_resource` method in the controller: + +```ruby +module Madmin + class PostsController < Madmin::ResourceController + private + + def scoped_resources + super.includes(:user) + end + end +end + +``` + ## Configuring Views The views packaged within the gem are a great starting point, but inevitably people will need to be able to customize those views. @@ -47,16 +65,19 @@ The views packaged within the gem are a great starting point, but inevitably peo You can use the included generator to create the appropriate view files, which can then be customized. For example, running the following will copy over all of the views into your application that will be used for every resource: + ```bash rails generate madmin:views ``` -The view files that are copied over in this case includes all of the standard Rails action views (index, new, edit, show, and _form), as well as: -* `application.html.erb` (layout file) -* `_javascript.html.erb` (default JavaScript setup) -* `_navigation.html.erb` (renders the navigation/sidebar menu) +The view files that are copied over in this case includes all of the standard Rails action views (index, new, edit, show, and \_form), as well as: + +- `application.html.erb` (layout file) +- `_javascript.html.erb` (default JavaScript setup) +- `_navigation.html.erb` (renders the navigation/sidebar menu) As with the other views, you can specifically run the views generator for only the navigation or application layout views: + ```bash rails g madmin:views:navigation # -> app/views/madmin/_navigation.html.erb @@ -68,6 +89,7 @@ rails g madmin:views:layout # Note the layout generator includes the layout, ja ``` If you only need to customize specific views, you can restrict which views are copied by the generator: + ```bash rails g madmin:views:index # -> app/views/madmin/application/index.html.erb @@ -79,6 +101,7 @@ The `attribute` method in model_resource.rb gives you that flexibility. ```bash # -> app/madmin/resources/book_resource.rb ``` + ```ruby class UserResource < Madmin::Resource attribute :id, form: false @@ -91,6 +114,7 @@ end ``` You can also scope the copied view(s) to a specific Resource/Model: + ```bash rails generate madmin:views:index Book # -> app/views/madmin/books/index.html.erb @@ -131,4 +155,5 @@ access your madmin panel: [Authentication Docs](docs/authentication.md) This project uses Standard for formatting Ruby code. Please make sure to run standardrb before submitting pull requests. ## 📝 License + The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).