4

嗨,我尝试在活动管理员中实现一个自己的控制器+它需要继承活动管理员的页脚/标题/面包屑

我需要一个用于常规索引操作的自己的模板文件...传递一个参数以显示相关统计信息(我将使用 google chart api 在模板中呈现它们)

我遇到的问题是没有办法从头开始期望侧边栏不会对我有很大帮助..

我需要在该视图上显示 7 个不同的图表

我真的很感激任何想法,因为它让我发疯

谢谢皮埃尔

4

2 回答 2

3

继上一个答案。你甚至不需要定义一个真实的模型(在你的模型文件夹中)。我需要让这个工作的最少代码是:

全部在一个文件中:app/admin/charts.rb

class Chart < ActiveRecord::Base
end

ActiveAdmin.register Chart do
  config.comments = false
  config.clear_action_items!
  before_filter do @skip_sidebar = true end


  controller do
    def index
      params[:action] = "Google Charts" # this sets the page title (so it doesnt just render 'index')
      render 'admin/charts/index', :layout => 'active_admin' # renders the index view in app/views/admin/charts
    end
  end
end

我将它用于这个要点: https ://gist.github.com/1644526

于 2012-01-20T03:00:48.220 回答
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-12T14:00:43.173 回答