简体   繁体   English

将页面添加到活动管理员

[英]Add page to active admin

We are wanting to add a help page to our admin and we are using the active admin gem.我们想向我们的管理员添加一个帮助页面,我们正在使用活动的管理 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.此页面未与任何模型相关联,因此我正在努力弄清楚如何让链接显示在每个页面的菜单栏中。

I know I'm a little late, but I usually am :D.我知道我有点晚了,但我通常是: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这里是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

Warning: this is hopelessly outdated, and not relevant in 2020 anymore.警告:这已经过时了,在 2020 年不再相关。 This was for activeadmin <0.7 versions.这是针对 activeadmin <0.7 版本的。

Make a file /app/models/help.rb with this contents, for more advanced tableless models you might want to check outhttp://keithmcdonnell.net/activerecord_tableless_model_gem.html or google your own insight together.使用此内容创建一个文件 /app/models/help.rb,对于更高级的无表模型,您可能需要查看http://keithmcdonnell.net/activerecord_tableless_model_gem.html或谷歌一起搜索您自己的见解。

class Help < ActiveRecord::Base

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

  # ...  

end

add an entry to /config/initializers/inflections.rb向 /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:在 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 注册块(确保您在正确的位置创建了一个视图部分)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM