我们想在我们的管理员中添加一个帮助页面,我们使用的是Active admin gem。 这个页面不与任何模型相关联,所以我正在努力尝试如何让链接显示在每个页面的菜单栏中。
警告:这是无可救药的过时,在2020年已经不相关了。这是为activeadmin <0.7版本。
用这个内容做一个文件appmodelshelp.rb,对于更高级的无表模型,你可能想看看。http:/keithmcdonnell.netactiverecord_tableless_model_gem.html。 或一起google自己的见解。
class Help < ActiveRecord::Base
def self.columns
@columns ||= []
end
# ...
end
在configinitializersinflections.rb中添加一个条目。
ActiveSupport::Inflector.inflections do |inflect|
inflect.uncountable %w( help )
end
在configroutes.rb中为你的viewlogger设置一个路由。
match '/admin/help' => 'admin/help#index', :as => :admin_help
现在你可以按照以下方式制定activeadmin注册块(确保你在正确的地方创建了一个view partial)。
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
我知道我有点晚了,但我通常都是这样的: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