Namespaces and routing conventions

coyote edited this page Sep 13, 2010 · 7 revisions

Namespaces

Tog and its plugins use different namespaces for their functionality, depending on the user’s role. They are: site, member and admin.

Site

This namespace is the “public” face of the social network. Registered and not registered users can interact with any content in this area (if they are allowed to). For example, in a blog, they can see the blog’s posts, comment them, etc. Classes in this namespace normally fall into a plugin’s namespace, without any other special namespace (ex: Conversatio::BlogsController) and its routes doesn’t add any special folders:

toginstallation.com/conversatio/blogs/1

Members

In this area each user has access to its own content and data. For example, in a blog, a member will be able to add or edit a post, or approve moderated comments. If we are talking about groups, in this area a group moderator could approve new users, edit the group’s description, etc.
By convention, member controllers and actions live on “/member/PLUGIN/xxx” urls, for example:

toginstallation.com/member/messages/show/1

These controllers are normally in the namespace Member::PLUGIN_NAME, and you’ll normally create one by extending the Member::BaseController class. For example: Member::Conversatio::PostsController

Admin

This area is designed for the site & social network’s admins. The user has to be an admin of the site to be able to access this area.. For example, in a blog system, an administrator in this meta area will be able to suspend or delete a blog.
By convention, member controllers and actions should live on “/admin/PLUGIN/xxx” urls, for example:

toginstallation.com/admin/users/1

These controllers are normally in the namespace Admin::PLUGIN_NAME, and you’ll normally create one by extending the Admin::BaseController class. For example: Admin::Abusorama::AbuseController

Layouts

Each of the namespaces uses its own layout for its content. This is added by just extending the BaseController of its namespace, so you don’t need to worry about it.

namespace layout
site application.html.erb
member member.html.erb
admin admin.html.erb

Just in case, there is one other layout, called session.html.erb which is used for sign-in and sign-up processes.