GithubHelp home page GithubHelp logo

active_admin_menu's Introduction

ActiveAdminMenu

Manageable menu with YAML for Active Admin

Installation

Add this line to your application's Gemfile:

gem 'active_admin_menu'

And then execute:

$ bundle

Or install it yourself as:

$ gem install active_admin_menu

Usage

Install and prepare Rails and ActiveAdmin before install active_admin_menu with bundle, and run it:

$ bundle exec rails generate active_admin_menu:install
create  config/initializers/active_admin_menu.rb
create  config/active_admin_menu.yml

And edit config/active_admin_menu.yml:

default: &default
  root:
    - Dashboard
  Admin:
    - AdminUser

development:
  <<: *default

test:
  <<: *default

production:
  <<: *default

And edit config/locales/en.yml:

en:
  active_admin:
    menu:
      admin: Administrator
      dashboard: Admin Dashboard

Configuration

See config/initializers/active_admin_menu.rb:

ActiveAdminMenu.configure do |config|
  config.source                     = Rails.root.join("config", "active_admin_menu.yml")
  config.namespace                  = Rails.env
  config.uncategorize_key_name      = "root"
  config.i18n_scope_prefix[:parent] = "active_admin.menu"
  config.i18n_scope_prefix[:label]  = "active_admin.menu"
end
attribute type content
source /path/to/yaml or Hash Source of menu
namespace String The key of source
uncategorize_key_name String Uncategorize key name (default: root)
i18n_scope_prefix[:parent] String Looking up i18n scope for parent
i18n_scope_prefix[:label] String Looking up i18n scope for register_page

If the resource is not register_page, label will translate from activerecord.models on locale.

Tips

How to sort menu links on top level?

It' impossible to sort by priority option. So you need to add numeric prefix on i18n keys.

You need to change like this:

en:
  active_admin:
    menu:
      user: "01 User"
      admin: "02 Admin"
      dashboard: "Dashboard"

License

MIT License

active_admin_menu's People

Contributors

iwaseasahi avatar yhirano55 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

active_admin_menu's Issues

How to add label to a child item

Thank you for your great work.
It's awsome.

Btw, I have a question.
I'm trying to put a label on a child item.
I tried some ways to do that.
But, they doesn't work.

How should I write in active_admin_menu.yml?

With Ruby 3.1, YAML.load_file is not possible.

Steps to reproduce

With Ruby 3.1, the following code causes an error.

def source=(value)
@source = value.is_a?(Hash) ? value : YAML.load_file(value.to_s)
end

 Psych::BadAlias: Unknown alias: default

Cause

Ruby 3.1 uses Psych 4 by default, and Psych.load of Psych 4 no longer loads alias by default.

See below for details.
https://secret-garden.hatenablog.com/entry/2021/05/23/200803

System configuration

Ruby version: 3.1 or higher

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.