Admin Concept #1 - separate namespace in url (i.e., /admin)
When adding an admin namespace, the following steps should be followed:
- change routes
- setup new directory structure in app/
- change views to reflect new namespace
- secure access to the new admin namespace
1. Change your routes to reflect the new namespace. for instance:
map.namespace :admin do |admin|
admin.resources :posts
admin.resources :categories
admin.resources :forums
admin.resources :products
end
Just for fun, run rake routes in your app, and look at all of your new lovely routes!
2. Include a new admin directory under your app/controller, app/views and app/helpers. E.g., app/controller/admin/nameofcontroller.rb.
You will need to change the first line of your code to read: class Admin::YourController < ApplicationController
Any redirects in your controller code must be changed to reflect your new namespace. simply replace your existing @variable with [:admin, @your_variable] in the redirect. This code will redirect to the proper show method.
3. For any new or edit views, you need to change your form_for to reflect your new namespace as well. Changing the @variable again to reflect the new [:admin, @variable] should do the trick in most cases.
Also, your routes have changed, so you will need to change your restful routes in all of your new admin/model views. Usually you only need to add "admin_" to the existing route. e.g., posts_path would become admin_posts_path.
Concept #2 - inline administration.
Allows users to administer their site based on their user Id. If the user is set to admin in the database, then more options appear on their profile.
That user would then have access to /settings, for instance, because of their admin status.
The Settings model would be set up as usual, i.e., no namespace needed, but a before_filter would be used to allow access only to that admin user.
Question: Is there a third concept? What other ways can be used to allow for an admin "area"? Please post your comments, as I would love to hear your thoughts.
Thanks. I found this helpful. Keep up the good work.
ReplyDeleteExcellent, I was wondering what the best way of doing this was and you just answered the question.
ReplyDeleteThanks again!