# Edge, RESTful controllers and an admin section. How?

**URL:** <https://www.ruby-forum.com/t/edge-restful-controllers-and-an-admin-section-how/82598>\
**Category:** Rails\
**Created:** [January 19, 2007, 4:31pm UTC](https://www.ruby-forum.com/t/edge-restful-controllers-and-an-admin-section-how/82598 "2007-01-19T16:31:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![goodieboy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ecc23a/32.png) [@goodieboy](https://www.ruby-forum.com/u/goodieboy)\
**Post date:** [January 19, 2007, 4:31pm UTC](https://www.ruby-forum.com/t/edge-restful-controllers-and-an-admin-section-how/82598/1 "2007-01-19T16:31:34Z")

</div>

Hi,

Just started using rails, and am using edge. I’d like to have an area  
(url location) of the site that manages the models (products, product  
options, categories, orders, content etc.). My first thought (products  
for example) was to create an AdminProductController controller, that  
would extend the ProductController that was generated by using  
scaffold\_resource script. Then, in the ProductController I would  
specify with a filter which actions should be protected. Would doing  
this, “trick” Rails into getting me the correct views and layouts? It  
seems backwards to me, to put the authorization in the generated  
ProductController.

Is it still RESTful to have a url like: /admin/product/1;edit ???

Or do I switch the view and layout and allowed actions based on the  
user authentication and go with /product/1;edit - for some reason that  
bothers me?

So… I have the ProductController, a set of public views with a set of  
actions, a set of admin views and set of actions, and different layouts  
for each public and admin views. How is this done now with the new REST  
stuff? Would someone be so kind as to actually post an example? Please?  
🙂 I’m confused!

Thank you!

- matt

---

<div class="post-metadata">

**Author:** ![goodieboy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ecc23a/32.png) [@goodieboy](https://www.ruby-forum.com/u/goodieboy)\
**Post date:** [September 25, 2007, 10:48pm UTC](https://www.ruby-forum.com/t/edge-restful-controllers-and-an-admin-section-how/82598/2 "2007-09-25T22:48:45Z")

</div>

Yes, Virginia, you can have RESTful controllers inside an admin section.  
First thing is to make sure you’re creating your controllers correctly.

script/generate controller Admin/Products

This will generate Admin::ProductsController. I find it easier to have  
them  
all descend from a Admin::CommonController which in turn descends from  
ActiveRecord::Base, that way they can all inherit admin actions from  
Admin::CommonController instead of having to add them to each admin  
controller. Note: Admin/Products needs to be plural because you’re going  
to  
end up mapping the products resources in routes.rb as plural. At least,  
that’s the way it’s set up.

Next, you’ll need your [admin] routes set up like this:

map.with\_options :path\_prefix =\> “/admin”, :name\_prefix =\> “admin” do  
|m|  
m.resources :products, :controller =\> “admin/products”  
end

Notice you have to tell it to use the “admin/products” controller  
manually.  
It would look for “products” controller without it. Also, you need to  
use  
the :path\_prefix to make the route include the initial “/admin” part of  
the  
URI. You don’t have to use the :name\_prefix but I find it’s handy  
because it  
allows you to reuse the named route “products\_url” for another  
[non-admin]  
controller. However, it does create named routes like the oddly ordered  
admin\_new\_product\_url. Your call on which way you prefer that.

Hope that helps.

RSL

---

<div class="post-metadata">

**Author:** ![goodieboy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ecc23a/32.png) [@goodieboy](https://www.ruby-forum.com/u/goodieboy)\
**Post date:** [September 25, 2007, 10:49pm UTC](https://www.ruby-forum.com/t/edge-restful-controllers-and-an-admin-section-how/82598/3 "2007-09-25T22:49:31Z")

</div>

To be honest, I don’t remember where I found the documentation about  
map.with\_options. I know there’s a blog post somewhere out there that I  
learned more about it but I first found it when I was going through the  
source code for Mephisto. If you combine the info in the REST-y Rails  
cheatsheet  
[[http://nubyonrails.com/articles/2006/10/09/peepcode-rest-basics](http://nubyonrails.com/articles/2006/10/09/peepcode-rest-basics)]  
and this post,  
[[苏州匠陀房产交易有限公司](http://www.pinupgeek.com/2006/5/24/rails-routing-demystified)]  
you should be able to interpolate the rest. Hope that helps.

RSL

---

<div class="post-metadata">

**Author:** ![goodieboy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ecc23a/32.png) [@goodieboy](https://www.ruby-forum.com/u/goodieboy)\
**Post date:** [September 25, 2007, 11:10pm UTC](https://www.ruby-forum.com/t/edge-restful-controllers-and-an-admin-section-how/82598/4 "2007-09-25T23:10:19Z")

</div>

I was like looking for something similar aswell thanks for the tip.

You can also found out about map.with\_options here

[http://api.rubyonrails.com/classes/ActionController/Routing.html](http://api.rubyonrails.com/classes/ActionController/Routing.html)

cheers.

---

<div class="post-metadata">

**Author:** ![goodieboy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ecc23a/32.png) [@goodieboy](https://www.ruby-forum.com/u/goodieboy)\
**Post date:** [September 25, 2007, 10:52pm UTC](https://www.ruby-forum.com/t/edge-restful-controllers-and-an-admin-section-how/82598/5 "2007-09-25T22:52:11Z")

</div>

Ahh, I didn’t see this post until now! Thank you very much. I was  
almost in tears. Where can I find more information on the map object? I  
don’t know what map.with\_options does?

- matt
