Forum: Ruby on Rails Edge, RESTful controllers and an admin section. How?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
444c7d8579d3389a76c8497f5cb66c13?d=identicon&s=25 goodieboy (Guest)
on 2007-01-19 16:31
(Received via mailing list)

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

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
70225136eacd3d870f64e03bff678655?d=identicon&s=25 Russell Norris (Guest)
on 2007-09-25 22:48
(Received via mailing list)
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
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
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.resources :products, :controller => "admin/products"

Notice you have to tell it to use the "admin/products" controller
It would look for "products" controller without it. Also, you need to
the :path_prefix to make the route include the initial "/admin" part of
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
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.

70225136eacd3d870f64e03bff678655?d=identicon&s=25 Russell Norris (Guest)
on 2007-09-25 22:49
(Received via mailing list)
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
and this post,
you should be able to interpolate the rest. Hope that helps.

444c7d8579d3389a76c8497f5cb66c13?d=identicon&s=25 M.W. Mitchell (goodieboy)
on 2007-09-25 22:52
(Received via mailing list)
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
89249c299e024f4ac4452aabea1b2be7?d=identicon&s=25 Josh (Guest)
on 2007-09-25 23:10
(Received via mailing list)
I was like looking for something similar aswell thanks for the tip.

You can also found out about map.with_options here

This topic is locked and can not be replied to.