Skip to content
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

avoid n+1 & readme formatting #240

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -40,23 +41,43 @@ 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.

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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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).