简体   繁体   English

自动检测新控制器以向菜单添加动作

[英]Auto-detect new controllers to add actions to menu

I am developing a Rails 3 application that will have an admin area with a side menu (similar to the Wordpress admin menu.) 我正在开发一个Rails 3应用程序,该应用程序将具有一个带有侧面菜单的管理区域(类似于Wordpress的管理菜单。)

I was wondering what the best method would be to have rails automatically detect when a new controller is added to the admin and add the appropriate actions to the menu. 我想知道最好的方法是让rails自动检测何时将新的控制器添加到管理员并将适当的操作添加到菜单。

Anything about 'Admin' needs to be done? 关于“管理员”的任何事情都需要做吗? It's best that you use Active Admin 最好使用Active Admin

It will take care of your problem too. 它也会解决您的问题。 I would highly recommend that you check it out. 我强烈建议您检查一下。

You can get a list of controllers with this code: 您可以使用以下代码获取控制器列表:

Rails.application.routes.routes.map do |route| route.defaults[:controller] end

Inspect the output, as it will give you duplicate results, filter them and you can use it. 检查输出,因为它将为您提供重复的结果,对其进行过滤,然后就可以使用它。

As a side note: are you sure you want all controllers in your admin interface? 附带说明:您确定要在管理界面中使用所有控制器吗? It makes no sense, maybe you should try Active Admin, has suggested earlier. 这是没有意义的,也许您应该尝试Active Admin,前面已经建议过。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM