GithubHelp home page GithubHelp logo

activeadmin-menus's Introduction

ActiveAdmin Menus

⚠️ Unmaintained ⚠️

Sorry, but I no longer work on ActiveAdmin often enough to justify mantaining this gem. Take it as it is. If you are interested to update and maintain the gem, please let me know! ❤️

Installation

gem 'activeadmin-menus', github: "stefanoverna/activeadmin-menus", branch: "master"
rails g active_admin:menus:install
rake db:migrate

Basic usage

Edit app/admin/menus.rb to your needs:

ActiveAdmin::Menus.configure do |c|
  # Areas are specific parts of a page layout, you can add many of them
  c.add_area :main_navigation
  
  c.add_predefined_item :home do |i|
    # Specify how to render the menu item
    i.renderer = lambda { link_to 'Home', root_path }
  end
  
  c.add_resource_class Page do |i|
    # Specify how to render the menu item
    i.renderer = lambda { |page| link_to page.title, page }
  end
end

Advanced usage

Areas

c.add_area :header do |a|
  # This wraps lists of sibling items
  # `content` is the list of sibling items
  # `item` is the parent item (when rendering the root menu items, it will be nil)
  a.list_wrapper = lambda { |content, item| content_tag(:ul, content) }

  # This wraps the single menu item
  a.item_wrapper = lambda { |content, active, item| content_tag(:li, content) }

  # This specifies how to render custom (i.e. Label + URL) menu items
  a.custom_item_renderer = lambda { |item| link_to(item.label, item.url) }
end

Resource items

c.add_resource_class Page do |i|
  # This specifies the method to call to retreive the list of resources that 
  # can be used to build menu items. Lambdas are also allowed
  # i.collection = lambda { Page.all }
  i.collection = :all

  # This specifies how to render a resource into the menu.
  i.renderer = lambda { |page, active, item| link_to page.title, page }

  # This specifies if the menu item is active for the current request
  i.active_if = lambda { |page, item| controller_name == "pages" && action_name == "show" }
end

Predefined menu items

c.add_predefined_item :home do |i|
  # This specifies how to render the item into the menu
  i.renderer = lambda { |active, item| link_to active, 'Home', root_path }

  # This specifies if the menu item is active for the current request
  i.active_if = lambda { |item| action_name == "homepage" }
end

Available/overridable helpers

See lib/active_admin/menus/helpers.rb for the complete list of overridable helpers.

active_menu_item_attributes(active)

This specifies the standard way to define an active menu item. Defaults to {class: 'active'}

active_link_to(active, label, url)

Default renderers use this method to produce links. Active links will use active_menu_item_attributes.

render_menu(area)

This renders a complete menu for the specified area.

activeadmin-menus's People

Contributors

mzampetti avatar stefanoverna avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

activeadmin-menus's Issues

Strong Parameters?

Seems to have issues with strong parameters. So for example i had to do this to be able to create a menu:

ActiveAdmin.register Menu do
    permit_params :name, :area
end
ActiveAdmin::Menus.configure do |c|
  # Areas are specific parts of a page layout, you can add many of them
  c.add_area :main_navigation do |i|

  end

  c.add_predefined_item :home do |i|
    # Specify how to render the menu item
    i.renderer = lambda { link_to 'Home', root_path }
  end

  c.add_resource_class Page do |i|
    # Specify how to render the menu item
    i.renderer = lambda { |page| link_to page.title, page }
  end
end

but then I can't create a resource menu item with error:

ActiveModel::ForbiddenAttributesError

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.