Understanding controllers

You’ll have to forgive me … I’ve been toying with rails for about a
week
and although I don’t feel completely lost there’s still a lot that I
don’t
understand. Here goes.

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

http://example.com/admin/product/
http://example.com/admin/product/edit/1
http://example.com/admin/category/new
http://example.com/admin/warehouse/show/16

… rather than just simply:

http://example.com/admin/edit/1
http://example.com/admin/list
http://example.com/admin/show/16

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

http://example.com/products/1
http://example.com/categories/23

etc.

In my first example, are product, category and warehouse controllers as
well? Or are they actions of the admin controller? If they are actions,
how
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.

On Thu, 2006-02-23 at 23:39 -0500, Greg MacGregor wrote:

http://example.com/admin/product/edit/1
accessed like so:
actions for each?

Hope my explanation makes sense. Any help appreciated.


actually, I don’t think you would normally do …

http://example.com/admin/product/edit/1

but would simply do

http://example.com/admin/edit/1

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.

Craig

On Thu, Feb 23, 2006 at 11:39:12PM -0500, Greg MacGregor wrote:

http://example.com/admin/category/new
http://example.com/admin/warehouse/show/16

… rather than just simply:

http://example.com/admin/edit/1
http://example.com/admin/list
http://example.com/admin/show/16
[…]

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
etc…


- Adam

** Expert Technical Project and Business Management
**** System Performance Analysis and Architecture
****** [ http://www.everylastounce.com ]

[ Adam Fields (weblog) - - entertaining hundreds of millions of eyeball atoms every day ] … Blog
[ Adam Fields Resume ]… Experience
[ Adam Fields | Flickr ] … Photos
[ http://www.aquicki.com/wiki ]…Wiki
[ http://del.icio.us/fields ] … Links

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])
end

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

Greg

On 2/23/06, Craig W. [email protected] wrote:

actions, how do I go about creating the CRUD interface that reacts to

Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Greg MacGregor
Web D.
416-516-0395
www.sixminutes.ca

def edit_cat
@category = Category.find(params[:id])
end

http://example.com/admin/edit_cat/1

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

Craig