Forum: Ruby on Rails Understanding controllers

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.
Greg MacGregor (Guest)
on 2006-02-24 06:41
(Received via mailing list)
You'll have to forgive me ... I've been toying with rails for about a
and although I don't feel completely lost there's still a lot that I
understand. Here goes.

Assume I have a controller called admin in app/controllers as well as
model classes in app/models: product, category, warehouse. How exactly
do I
use the admin controller to produce this kind of structure?

... rather than just simply:

Keep in mind that "admin" is password protected and public content is
accessed like so:


In my first example, are product, category and warehouse controllers as
well? Or are they actions of the admin controller? If they are actions,
do I go about creating the CRUD interface that reacts to each action? In
other words, how do i attach edit, show, list etc actions for each?

Hope my explanation makes sense. Any help appreciated.
Craig W. (Guest)
on 2006-02-24 06:51
(Received via mailing list)
On Thu, 2006-02-23 at 23:39 -0500, Greg MacGregor wrote:
> accessed like so:
> actions for each?
> Hope my explanation makes sense. Any help appreciated.
actually, I don't think you would normally do ...

but would simply do

but since your questions pretty much follow the methodology of the Agile
book, why not buy the PDF or the book and run through it as it is almost
done exactly the way you are asking and would probably reduce your
learning curve.

Adam F. (Guest)
on 2006-02-24 06:54
(Received via mailing list)
On Thu, Feb 23, 2006 at 11:39:12PM -0500, Greg MacGregor wrote:
> ... rather than just simply:

You could use just one controller and use custom routes to pick out
the objects you want to edit.

A better alternative is probably to have individual controllers for
each object, in an admin module. You can have multiple controllers
that utilize the same model.

$ ruby script/generate controller "admin/product"

Check out the help by calling each of the generate commands with no
arguments for more information on this:

$ ruby script/generate controller
$ ruby script/generate model
$ ruby script/generate scaffold

				- Adam

** Expert Technical Project and Business Management
**** System Performance Analysis and Architecture
****** [ ]

[ ] ............ Blog
[ ].. Experience
[ ] ... Photos
[ ].............Wiki
[ ] ............. Links
Greg MacGregor (Guest)
on 2006-02-24 07:00
(Received via mailing list)
Funny thing is that I have the book open in front of me! In the examples
within, something like admin/edit assumes:

def edit
    @product = Product.find(params[:id])

... Ok. No sweat. But what if i don't want to edit a product ... how
about a
catgeory instead?


On 2/23/06, Craig W. <removed_email_address@domain.invalid> wrote:
> >
> >
> > actions, how do I go about creating the CRUD interface that reacts to
> Rails mailing list
> removed_email_address@domain.invalid

Greg MacGregor
Web D.
Craig W. (Guest)
on 2006-02-24 07:03
(Received via mailing list)
def edit_cat
  @category = Category.find(params[:id])

assuming of course that you have a categories table/category model

This topic is locked and can not be replied to.