活动管理 - 非资源相关控制器

发布于 2024-12-11 15:46:23 字数 223 浏览 0 评论 0原文

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

我需要一个自己的模板文件来执行常规索引操作...传递参数以显示相关统计信息(我会使用谷歌图表API在模板中渲染它们)

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

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

我真的很欣赏任何想法,因为这让我发疯,

谢谢皮埃尔

Hy there, i try to implement a own controller into active admin + it would neet to inherit the footer / header / breadcrumbs of active admin

i need a own template file for the regular index action ... passing a parameter in to show related stats ( i would render them in the template using google chart api)

the issue i came accross is there is no way todo that from scratch expect sidebars which wont help me alot ..

i need to display like 7 different charts on that view

i realy appreciate any idea since it drives me insane

thanks Pierre

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暗喜 2024-12-18 15:46:23

进一步之前的答案。您甚至不需要定义真实的模型(在您的模型文件夹中)。
完成这项工作所需的最少代码是:

全部在一个文件中: 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

Further to the previous answer. You don't even need to define a real model (in your models folder).
The minimum code I needed to get this working was:

All in the one file: 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

I used it for this gist:
https://gist.github.com/1644526

揪着可爱 2024-12-18 15:46:23

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

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

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   

结尾

This is what worked for me, just substitute the right name for ViewLogger in the codeblocks. This way you wont have to create a dummy table in your database.

Make a file /app/models/viewlogger.rb with this contents, for more advanced tableless models you might want to check out http://keithmcdonnell.net/activerecord_tableless_model_gem.html or google your own insight together.

class Viewlogger < ActiveRecord::Base

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

  # ...  

end

add an entry to /config/initializers/inflections.rb

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

set up a route for your viewlogger, in config/routes.rb:

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

now you can formulate the activeadmin register block as follows (make you sure you create a view partial in the right place)

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   

end

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文