5

可能重复:
将页面添加到活动管理员

我目前正在寻找一种解决方案,用于向 ActiveAdmin(和 Rails 3.1)生成的管理员添加没有模型的控制器。当然我想在导航栏中添加一个新菜单。

使用ActiveAdmin.register MyControllerWithoutModel do不起作用。

编辑:这个问题是Add page to active admin但没有找到答案的副本。

4

2 回答 2

2

这对我有用,只需在代码块中用正确的名称替换ViewLogger。这样您就不必在数据库中创建一个虚拟表。

使用此内容创建文件 /app/models/viewlogger.rb,对于更高级的无表模型,您可能需要查看http://keithmcdonnell.net/activerecord_tableless_model_gem.html或一起谷歌自己的见解。

class Viewlogger < ActiveRecord::Base

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

  # ...  

end

向 /config/initializers/inflections.rb 添加一个条目

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

在 config/routes.rb 中为您的查看器设置一个路由:

match '/admin/viewlogger' => 'admin/viewlogger#index', :as => :admin_viewlogger

现在您可以按如下方式制定 activeadmin 注册块(确保在正确的位置创建部分视图)

ActiveAdmin.register Viewlogger 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/viewlogger/index', :layout => 'active_admin'
    end
  end   

结尾

于 2012-01-11T13:12:57.723 回答
0

我一直在寻找这个来编辑应用程序配置,但它似乎没有模型是不可能的。我刚刚在 db 中创建了带有表的空模型,并像往常一样注册了资源。

自定义资源:

禁用过滤器

config.clear_sidebar_sections!

自定义菜单路径

ActiveAdmin.application.namespaces[:admin].resources['Configuration'].namespace.menu.items.each{|i| i.instance_eval('@cached_url[:admin_configurations_path] = "/admin"')}
于 2011-10-21T19:02:16.490 回答