# RESTful admin interface? how?

**URL:** <https://www.ruby-forum.com/t/restful-admin-interface-how/123226>\
**Category:** Rails\
**Created:** [December 15, 2007, 2:19am UTC](https://www.ruby-forum.com/t/restful-admin-interface-how/123226 "2007-12-15T02:19:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JSPablo\_FernSSSSnd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9bcb4/32.png) [@JSPablo\_FernSSSSnd](https://www.ruby-forum.com/u/JSPablo_FernSSSSnd)\
**Post date:** [December 15, 2007, 2:19am UTC](https://www.ruby-forum.com/t/restful-admin-interface-how/123226/1 "2007-12-15T02:19:30Z")

</div>

Hello,

So I have a web site with companies and products. I use REST and make  
companies a resource and products a resource (and a ‘sub-resource’ of  
company). But only for viewing, no new, no create, no destroy, no  
update. Now  
I want to offer an admin interface that would be essentially the same  
but  
with an URL prefix of /my/ to the URL, same models, but that are viewed  
differently. Only the owned companies and products are shown (being  
logged in  
is a requirement for everything in /my/), the interface would be  
different,  
and it would allow create, destroy, update, etc. What is the RESTful way  
to  
do it?

Thank you.

---

<div class="post-metadata">

**Author:** ![JSPablo\_FernSSSSnd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9bcb4/32.png) [@JSPablo\_FernSSSSnd](https://www.ruby-forum.com/u/JSPablo_FernSSSSnd)\
**Post date:** [December 15, 2007, 3:41am UTC](https://www.ruby-forum.com/t/restful-admin-interface-how/123226/2 "2007-12-15T03:41:14Z")

</div>

J. Pablo FernÃ¡ndez wrote:

> Hello,
> 
> So I have a web site with companies and products. I use REST and make  
> companies a resource and products a resource (and a ‘sub-resource’ of  
> company). But only for viewing, no new, no create, no destroy, no  
> update. Now  
> I want to offer an admin interface that would be essentially the same  
> but  
> with an URL prefix of /my/ to the URL, same models, but that are viewed  
> differently. Only the owned companies and products are shown (being  
> logged in  
> is a requirement for everything in /my/), the interface would be  
> different,  
> and it would allow create, destroy, update, etc. What is the RESTful way  
> to  
> do it?
> 
> Thank you.

Rails 2.0 has namespaced routes that will create an additional  
controller in a subfolder named after the namespace, ex:  
./script/generate controller my::companies

will create a companies controller in the “my” folder, or so I have read

---

<div class="post-metadata">

**Author:** ![JSPablo\_FernSSSSnd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9bcb4/32.png) [@JSPablo\_FernSSSSnd](https://www.ruby-forum.com/u/JSPablo_FernSSSSnd)\
**Post date:** [December 15, 2007, 8:18am UTC](https://www.ruby-forum.com/t/restful-admin-interface-how/123226/3 "2007-12-15T08:18:25Z")

</div>

Would you know any online resources or online tutorails that teach how  
to do this?

Elle

On Dec 15, 1:41 pm, Chris O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![JSPablo\_FernSSSSnd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9bcb4/32.png) [@JSPablo\_FernSSSSnd](https://www.ruby-forum.com/u/JSPablo_FernSSSSnd)\
**Post date:** [December 15, 2007, 11:35am UTC](https://www.ruby-forum.com/t/restful-admin-interface-how/123226/4 "2007-12-15T11:35:09Z")

</div>

On Saturday 15 December 2007 02:41:14 Chris O. wrote:

> > differently. Only the owned companies and products are shown (being  
> > controller in a subfolder named after the namespace, ex:  
> > ./script/generate controller my::companies
> 
> will create a companies controller in the “my” folder, or so I have read

Yes, I’ve used to use that method in Rails 1.2, but I’m not sure it’ll  
lead to  
proper RESTful resources now.

---

<div class="post-metadata">

**Author:** ![JSPablo\_FernSSSSnd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9bcb4/32.png) [@JSPablo\_FernSSSSnd](https://www.ruby-forum.com/u/JSPablo_FernSSSSnd)\
**Post date:** [December 15, 2007, 11:38am UTC](https://www.ruby-forum.com/t/restful-admin-interface-how/123226/5 "2007-12-15T11:38:08Z")

</div>

On Saturday 15 December 2007 07:18:03 elle wrote:

> Would you know any online resources or online tutorails that teach how  
> to do this?

What do you exactly mean by “this”? If you mean learn RESTful Rails,  
I’ve  
learnt with [http://b-simple.de/download/restful\_rails\_en.pdf](http://b-simple.de/download/restful_rails_en.pdf)

---

<div class="post-metadata">

**Author:** ![JSPablo\_FernSSSSnd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9bcb4/32.png) [@JSPablo\_FernSSSSnd](https://www.ruby-forum.com/u/JSPablo_FernSSSSnd)\
**Post date:** [December 15, 2007, 11:45am UTC](https://www.ruby-forum.com/t/restful-admin-interface-how/123226/6 "2007-12-15T11:45:09Z")

</div>

DHH talked about this in the RailsConf keynote, which you can read about  
here:

[http://casperfabricius.com/blog/wp-content/uploads/2007/09/keynote-dhh.txt](http://casperfabricius.com/blog/wp-content/uploads/2007/09/keynote-dhh.txt)

basically you add the following to your routes file:

map.namespace :admin do |admin|  
admin.resources :orders, :member =\> { :resend =\> :post }  
admin.resources :users, :collection =\> { :filter =\> :any }  
end

#want to allow public access to certain methods for orders and users  
map.resources :orders, :users

then you’ll have a admin/users\_controller.rb and  
admin/orders\_controller.rb files, as well as the public  
users\_controller and orders\_controller. Your restful paths will look  
like the following:

admin/users  
admin/users/new  
admin/users/edit

admin/orders/  
admin/orders/edit  
etc

so you stick your index and show methods in your public  
users\_controller, and put the admin index, create, update, etc, new,  
etc into the admin/users\_controller.

Adam
