【问题标题】:Add page to active admin将页面添加到活动管理员
【发布时间】:2011-10-03 19:54:54
【问题描述】:

我们想为我们的管理员添加一个帮助页面,并且我们正在使用活动的管理员 gem。此页面未与任何模型关联,因此我正在努力弄清楚如何让链接显示在每个页面的菜单栏中。

【问题讨论】:

标签: ruby-on-rails ruby-on-rails-3 activeadmin


【解决方案1】:

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

【讨论】:

  • 它也在 Active Admin 文档中:activeadmin.info/docs/9-custom-pages.html 请注意,您需要一个相当新版本的 Active Admin 才能工作:我必须从 0.3.4 升级到 0.4.3
  • 第一个sn-p中的代码(使用register_page方法)应该放在哪里?
【解决方案2】:

警告:这已经过时了,在 2020 年不再适用。这适用于 activeadmin

使用此内容创建文件 /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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-27
    • 1970-01-01
    • 2018-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多