Module: ActiveAdmin::Resource::Menu

Included in:
Page, ActiveAdmin::Resource
Defined in:
lib/active_admin/resource/menu.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

Returns the value of attribute menu_item.



59
60
61
# File 'lib/active_admin/resource/menu.rb', line 59

def menu_item
  @menu_item
end

Instance Method Details

#add_to_menu(menu_collection) ⇒ Object



53
54
55
56
57
# File 'lib/active_admin/resource/menu.rb', line 53

def add_to_menu(menu_collection)
  if include_in_menu?
    @menu_item = menu_collection.add navigation_menu_name, menu_item_options
  end
end

#default_menu_optionsObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/active_admin/resource/menu.rb', line 24

def default_menu_options
  # These local variables are accessible to the procs.
  menu_resource_class = respond_to?(:resource_class) ? resource_class : self
  resource = self
  {
    id: resource_name.plural,
    label: proc { resource.plural_resource_label },
    url: proc { resource.route_collection_path(params, url_options) },
    if: proc { authorized?(Auth::READ, menu_resource_class) }
  }
end

#include_in_menu?Boolean

Should this resource be added to the menu system?

Returns:

  • (Boolean)


62
63
64
# File 'lib/active_admin/resource/menu.rb', line 62

def include_in_menu?
  @include_in_menu != false
end


20
21
22
# File 'lib/active_admin/resource/menu.rb', line 20

def menu_item_options
  @menu_item_options ||= default_menu_options
end

Set the menu options. To disable this menu item, call ‘menu(false)` from the DSL



9
10
11
12
13
14
15
16
17
18
# File 'lib/active_admin/resource/menu.rb', line 9

def menu_item_options=(options)
  if options == false
    @include_in_menu = false
    @menu_item_options = {}
  else
    @include_in_menu = true
    @navigation_menu_name = options[:menu_name]
    @menu_item_options = default_menu_options.merge options
  end
end


49
50
51
# File 'lib/active_admin/resource/menu.rb', line 49

def navigation_menu
  namespace.fetch_menu(navigation_menu_name)
end


40
41
42
43
44
45
46
47
# File 'lib/active_admin/resource/menu.rb', line 40

def navigation_menu_name
  case @navigation_menu_name ||= DEFAULT_MENU
  when Proc
    controller.instance_exec(&@navigation_menu_name).to_sym
  else
    @navigation_menu_name
  end
end


36
37
38
# File 'lib/active_admin/resource/menu.rb', line 36

def navigation_menu_name=(menu_name)
  self.menu_item_options = { menu_name: menu_name }
end