这个问题在这里已经有了答案:
10年前关闭。
Possible Duplicate:
Add page to active admin
我目前正在寻找一种解决方案,用于向 ActiveAdmin(和 Rails 3.1)生成的管理员添加没有模型的 Controller 。
当然我想在导航栏中添加一个新菜单。
使用
ActiveAdmin.register MyControllerWithoutModel do
不工作。编辑:这个问题与 Add page to active admin 重复。但没有找到答案。
最佳答案
这对我有用,只需在代码块中用正确的名称替换 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 注册 block (确保在正确的位置创建部分 View )
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
结尾
关于ruby-on-rails - ActiveAdmin 如何添加没有模型的自定义 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7706122/