Best practice: same "workflow", different context

Hi,

I am trying to figure out what the best practice for the following
problem might be: In my RoR app, I have an account class, and the user
has to have the ability to edit it (e.g., change the email address). At
the same time, I want to give an admin the chance to edit it, because,
well, the targeted users might not be clever enough to do everything on
their own :wink:

Of course, the editing pages should look differently (different menu,
and also a different redirect after editing is complete). As a rails
newbie, I can figure out two basic ways of doing this:

  • use the same controller, and change the page layout and redirect_to
    according to some information stored in the session
  • use the same view, and have a different controller and layout for the
    user and the admin

I am not quite sure which way should be preferred - the first one
amounts to some case distinctions in the view and the controller, which
I do not like too much, and the second one produces redundant code in
the two controllers. Any suggestions, or maybe even a third possibility?

Thank you very much!

This is a tough question to answer. Basically it falls under the “Can
you admin using DRY”
Personally I try to create a different layout or use <% if
user.is_admin? %> blocks in the view.
Basically, you can do it any way, however to avoid rewriting as much
code as possible I use the if block method.
Here’s one resource I found right away.

http://www.ruby-forum.com/topic/136715