Rails 应用程序控制器的批评(随意严厉)
我编写了一个应用程序控制器,它可以处理我需要任何控制器完成的 99% 的任务。 我已将其发布在此处 (pastebin)。 就像我说的,随意严厉。
-更新:添加评论:)
谢谢,
-C
P.S. 我想说,我的目的是覆盖子类控制器中需要不同功能的方法,例如 _message 方法和 after_ 方法。 应用程序控制器将充当一种抽象类。 另外,一些 before_filters 是特定于插件的,例如tiny_mce和restful_authentication(恕我直言,这太棒了。)
I've written an application controller that handles 99% of what I need any controller to do. I've posted it here (pastebin). Like I said, feel free to be harsh.
-update: added comments :)
Thx,
-C
P.S. I would like to say that my intention here is to overwrite methods that need different functionality in sub-classed controllers, such as the _message methods and the after_ methods. The application controller will serve as a sort of abstract class. also, some of the before_filters are specific to plugins, such as tiny_mce and restful_authentication (which is awesome, imho.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不是您问题的答案,但如果您想朝这个方向更进一步,您可能需要看看 Hobo 。 它的 Hobo::ModelController 做了很多事情您的 ApplicationController 的作用。
This is not an answer to your question, but if you want to go further in this direction, you may want to take a look at Hobo. Its Hobo::ModelController does a lot of what your ApplicationController does.
小事,但我会将对象、模型和 model_name 方法设为私有或受保护。 除此之外我没有发现任何错误。
Small thing, but I would make the object, model, and model_name methods private or protected. Other than that I didn't notice any mistakes.