Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
M

madmin

> 后端框架
Open source

A robust Admin Interface for Ruby on Rails apps

761 stars0 likes5 views
WebsiteGitHub

About

A robust Admin Interface for Ruby on Rails apps

Madmin

A robust Admin Interface for Ruby on Rails apps

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
  • Works with Import maps and Sprockets

Installation

Add madmin to your application's Gemfile:

bash
bundle add madmin

Then run the madmin generator:

bash
rails g madmin:install

This will install Madmin and generate resources for each of the models it finds.

Resources

Madmin uses Resource classes to add models to the admin area.

Generate a Resource

To generate a resource for a model, you can run:

bash
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 ` for one resource, or `madmin.scopes.` shared across resources:

```yaml
en:
  madmin:
    scopes:
      post:
        published: Live

For labels that need logic (e.g. looking up a record name), override scope_label:

ruby
class PostResource  app/views/madmin/_navigation.html.erb

rails g madmin:views:layout  # Note the layout generator includes the layout, javascript, and navigation files.
 # -> app/views/madmin/application.html.erb
 # -> app/views/madmin/_javascript.html.erb
 # -> app/views/madmin/_navigation.html.erb

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

You might want to make some of your model's attributes visible in some views but invisible in others. The attribute method in model_resource.rb gives you that flexibility.

bash
 # -> app/madmin/resources/book_resource.rb
ruby
class BookResource  app/views/madmin/books/index.html.erb

Specifying Field Types

You can set a field type as the second argument. Field types may have additional options to render the field UI.

For example, we can use a select for the genre attribute and specify the collection of options to choose from.

ruby
class BookResource  app/views/madmin/fields/custom_field/_form.html.erb
# -> app/views/madmin/fields/custom_field/_index.html.erb
# -> app/views/madmin/fields/custom_field/_show.html.erb

You can then use this field on our resource:

ruby
class PostResource " link.

Unlike `member_action`, blocks receive **no** arguments. Each block is `instance_exec`-ed on the index view context, so `link_to`, route helpers, `policy`, `current_user`, `params`, `resource`, and `@records` are all available. Multiple blocks render in registration order.

Each block is responsible for its own authorization gating — if a button should be hidden for some users, guard it inside the block.

```ruby
class PostResource < Madmin::Resource
  collection_action do
    link_to "Bulk Import", bulk_import_admin_posts_path, class: "btn btn-secondary"
  end

  collection_action do
    link_to "Export CSV", export_admin_posts_path(format: :csv), class: "btn btn-secondary"
  end
end

Extending Madmin

Madmin runs ActiveSupport load hooks on its core classes so you can extend them from an initializer without reopening or monkey patching them. This is the recommended way for engines and gems to add behavior to Madmin.

Hook Base Use it for
:madmin_resource Madmin::Resource Adding to the resource DSL
:madmin_field Madmin::Field Shared behavior across every field type
:madmin_search Madmin::Search Customizing how the search query is built
:madmin_base_controller Madmin::BaseController Layouts, helpers, rescue_from, authentication
:madmin_resource_controller Madmin::ResourceController CRUD callbacks, scoping records, audit logging

Blocks are class_eval-ed on the base class, so self is the class itself:

ruby
# config/initializers/madmin.rb
ActiveSupport.on_load(:madmin_resource) do
  # self == Madmin::Resource, so `extend` adds class-level DSL to every resource
  extend MyAdmin::ResourceExtensions
end

ActiveSupport.on_load(:madmin_base_controller) do
  # self == Madmin::BaseController
  rescue_from Pundit::NotAuthorizedError, with: :admin_not_authorized
end

Hooks registered after a class has already loaded run immediately, so ordering in your initializers doesn't matter. The controllers live in the engine's app/ directory and are reloadable, which means their hooks re-run on every reload in development — keep the blocks idempotent.

Authentication

You can use a couple of strategies to authenticate users who are trying to access your madmin panel: Authentication Docs

Assets

You can customize the JavaScript and CSS assets used by Madmin for your application. To learn how see the Assets Doc

Contributing

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.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rubyadminadmin-dashboardhacktoberfestrails

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category后端框架
PricingOpen source

> Related tools

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架