开发者

Rails, Combine multiple controllers into one interface

In rails I am making a "blog" to help me learn. I was wondering how I could incorporate the editing, creating, and deletion of Users and Posts in my admin controller. I would also include deleting comments in there too. So far I have Users, Admin (basically just to login/con开发者_运维技巧trol everything),Comments, and posts. So how could I combine all of those into one Admin panel?


A controller should be per resource. Instead you could put multiple controllers under Admin namespace so that you can use admin/posts kind of URL. However, this way you'll have to write all your controller and view logic twice - once for admin, once for regular users. Combining any pages into "one panel" has nothing to do with your choice of controller structure. You will simply put links on a sidebar or on top of that panel, regardless of where the links will end up pointing to.

The easiest may be to allow editing/deleting resources conditionally, based on authorization. This way, instead of being confined to a panel you can be browsing the site like a regular user, except you'll see a few more buttons and have ability to edit/delete things. This means you can use all your already-written views and controllers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜