Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add page to active admin

We are wanting to add a help page to our admin and we are using the active admin gem. This page is not associated to any model so I am struggling trying to figure out how to get the link to show up in the menu bar on every page.

like image 790
Scott Avatar asked Oct 03 '11 19:10

Scott


People also ask

How does active admin work?

Active Admin is a Ruby on Rails plugin for generating administration style interfaces. It abstracts common business application patterns to make it simple for developers to implement beautiful and elegant interfaces with very little effort.


2 Answers

I know I'm a little late, but I usually am :D.

ActiveAdmin.register_page "Help" do

  content do
    panel "My Panel Test" do
      "Hello World"
    end
  end  


  sidebar "Test Sidebar" do
    "Hi World"
  end
end

Here's the corresponding code block in active_admin

# Register a page
#
# @param name [String] The page name
# @options [Hash] Accepts option :namespace.
# @&block The registration block.
#
def register_page(name, options = {}, &block)
  namespace_name = extract_namespace_name(options)
  namespace = find_or_create_namespace(namespace_name)
  namespace.register_page(name, options, &block)
end
like image 149
Jeff Ancel Avatar answered Sep 27 '22 16:09

Jeff Ancel


Warning: this is hopelessly outdated, and not relevant in 2020 anymore. This was for activeadmin <0.7 versions.

Make a file /app/models/help.rb with this contents, for more advanced tableless models you might want to check out http://keithmcdonnell.net/activerecord_tableless_model_gem.html or google your own insight together.

class Help < ActiveRecord::Base

  def self.columns 
    @columns ||= []
  end

  # ...  

end

add an entry to /config/initializers/inflections.rb

ActiveSupport::Inflector.inflections do |inflect|
  inflect.uncountable %w( help )
end

set up a route for your viewlogger, in config/routes.rb:

match '/admin/help' => 'admin/help#index', :as => :admin_help

now you can formulate the activeadmin register block as follows (make you sure you create a view partial in the right place)

ActiveAdmin.register Help do      
  config.comments = false
  before_filter do @skip_sidebar = true end
  # menu false
  config.clear_action_items!   # this will prevent the 'new button' showing up    
  controller do
    def index
      # some hopefully useful code
      render 'admin/help/index', :layout => 'active_admin'
    end
  end   

end
like image 34
Sjors Branderhorst Avatar answered Sep 27 '22 16:09

Sjors Branderhorst