ActiveAdmin如何添加不带模型的自定义控制器 [英] ActiveAdmin how to add a custom controller without model
问题描述
可能重复:
将页面添加到活动管理员
我目前正在寻找通过ActiveAdmin(和Rails 3.1)生成的将没有模型的控制器添加到管理中的解决方案。
当然,我想在导航栏中添加一个新菜单。
I currently looking to a solution for adding a controller without a model to the admin generate by ActiveAdmin (and Rails 3.1). Of course I'd like to add a new menu in the navbar.
使用 ActiveAdmin.register MyControllerWithoutModel do
不起作用。
编辑:此问题是将页面添加到活动管理员中,但未找到答案。
Edit : This question is a duplicate of Add page to active admin but no answer found.
推荐答案
这对我有用,只需替换为代码块中 ViewLogger 的正确名称。这样,您就不必在数据库中创建一个虚拟表。
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.
使用此内容创建文件/app/models/viewlogger.rb,以获得更高级的无表模型可能想查看 http://keithmcdonnell.net/activerecord_tableless_model_gem.html 或一起搜索您自己的见解。
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
将条目添加到/config/initializers/inflections.rb
add an entry to /config/initializers/inflections.rb
ActiveSupport::Inflector.inflections do |inflect|
inflect.uncountable %w( viewlogger )
end
设置路线对于您的Viewlogger,在config / routes.rb中:
set up a route for your viewlogger, in config/routes.rb:
match '/admin/viewlogger' => 'admin/viewlogger#index', :as => :admin_viewlogger
现在您可以按如下方式制定activeadmin注册块(确保您创建了部分视图
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
结束
这篇关于ActiveAdmin如何添加不带模型的自定义控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!