# Best practice: same "workflow", different context

**URL:** <https://www.ruby-forum.com/t/best-practice-same-workflow-different-context/139028>\
**Category:** Rails\
**Created:** [May 30, 2008, 6:47am UTC](https://www.ruby-forum.com/t/best-practice-same-workflow-different-context/139028 "2008-05-30T06:47:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![geek001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c57346/32.png) [@geek001](https://www.ruby-forum.com/u/geek001)\
**Post date:** [May 30, 2008, 6:47am UTC](https://www.ruby-forum.com/t/best-practice-same-workflow-different-context/139028/1 "2008-05-30T06:47:18Z")

</div>

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 😉

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!

---

<div class="post-metadata">

**Author:** ![geek001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c57346/32.png) [@geek001](https://www.ruby-forum.com/u/geek001)\
**Post date:** [May 30, 2008, 5:27pm UTC](https://www.ruby-forum.com/t/best-practice-same-workflow-different-context/139028/2 "2008-05-30T17:27:56Z")

</div>

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](http://www.ruby-forum.com/topic/136715)
