# Admin and standard controllers RESTFully

**URL:** <https://www.ruby-forum.com/t/admin-and-standard-controllers-restfully/130829>\
**Category:** Rails\
**Created:** [March 3, 2008, 6:45pm UTC](https://www.ruby-forum.com/t/admin-and-standard-controllers-restfully/130829 "2008-03-03T18:45:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JTJTJT](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ec9cab/32.png) [@JTJTJT](https://www.ruby-forum.com/u/JTJTJT)\
**Post date:** [March 3, 2008, 6:45pm UTC](https://www.ruby-forum.com/t/admin-and-standard-controllers-restfully/130829/1 "2008-03-03T18:45:40Z")

</div>

Hello. I will appreciate the opinion.

What is the standard way of separating admin functions from normal-  
user functions?

before\_filter in one controller?

Use two controllers, i.e. ProductController and Admin/  
ProductController?

I want to use map.resources so RESTFul would be better.

---

<div class="post-metadata">

**Author:** ![JTJTJT](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ec9cab/32.png) [@JTJTJT](https://www.ruby-forum.com/u/JTJTJT)\
**Post date:** [March 3, 2008, 8:01pm UTC](https://www.ruby-forum.com/t/admin-and-standard-controllers-restfully/130829/2 "2008-03-03T20:01:40Z")

</div>

I’m curious to this as well, as I am working on a RESTful site that  
needs to  
have admin-facing pages as well as end-user-facing pages.

I believe the “accepted” solution is to specify a specific layout if the  
user has administrative privileges - I’m guessing this would have to be  
done  
in the controller action, along the lines of:

def index

# Snip…

respond.do |format|  
format.html do  
render :layout =\> ‘admin’ if logged\_in\_user.is\_admin?  
# Normal user stuff  
end  
end  
end

However, that seems a little crufty to me and not as DRY as it could be  
(“wet”?) - but I am relatively new to Rails so I don’t know if it would  
be  
easier to use a before\_filter.

On Mon, Mar 3, 2008 at 12:41 PM, JT [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I want to use map.resources so RESTFul would be better.
> 
> >

–  
Wayne M.  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![JTJTJT](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ec9cab/32.png) [@JTJTJT](https://www.ruby-forum.com/u/JTJTJT)\
**Post date:** [March 4, 2008, 12:17am UTC](https://www.ruby-forum.com/t/admin-and-standard-controllers-restfully/130829/3 "2008-03-04T00:17:41Z")

</div>

People, people, just make a separate namespace in routing and make  
some REST controllers in there. You’ll thank yourself in the end.  
Trying to run multiple states through the same code paths (admin and  
user states) is just going to be a maintenance headache and will  
possibly eventually open security holes.

---

<div class="post-metadata">

**Author:** ![JTJTJT](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ec9cab/32.png) [@JTJTJT](https://www.ruby-forum.com/u/JTJTJT)\
**Post date:** [March 4, 2008, 7:37am UTC](https://www.ruby-forum.com/t/admin-and-standard-controllers-restfully/130829/4 "2008-03-04T07:37:24Z")

</div>

this was recently discussed on the list

[http://groups.google.com/group/rubyonrails-talk/browse\_thread/thread/5193c5af78810e42/2b9337ccc234f5c6](http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/5193c5af78810e42/2b9337ccc234f5c6)
