簡體   English   中英

將頁面添加到活動管理員

[英]Add page to active admin

我們想向我們的管理員添加一個幫助頁面,我們正在使用活動的管理 gem。 此頁面未與任何模型相關聯,因此我正在努力弄清楚如何讓鏈接顯示在每個頁面的菜單欄中。

我知道我有點晚了,但我通常是: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

這里是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

警告:這已經過時了,在 2020 年不再相關。 這是針對 activeadmin <0.7 版本的。

使用此內容創建一個文件 /app/models/help.rb,對於更高級的無表模型,您可能需要查看http://keithmcdonnell.net/activerecord_tableless_model_gem.html或谷歌一起搜索您自己的見解。

class Help < ActiveRecord::Base

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

  # ...  

end

向 /config/initializers/inflections.rb 添加一個條目

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

在 config/routes.rb 中為您的視圖記錄器設置路由:

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

現在您可以按如下方式制定 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