Forum: Ruby on Rails Understanding controllers

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C143acf82f94860ef6e2cba52b2de831?d=identicon&s=25 Greg MacGregor (Guest)
on 2006-02-24 05:41
(Received via mailing list)
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.
C1e5a9e9344b6d31b9df7303e6dc378a?d=identicon&s=25 Craig White (Guest)
on 2006-02-24 05:51
(Received via mailing list)
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
912436ffe7c27e25658a3f5f556a8c96?d=identicon&s=25 Adam Fields (Guest)
on 2006-02-24 05:54
(Received via mailing list)
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 ]

[ http://www.aquick.org/blog ] ............ Blog
[ http://www.adamfields.com/resume.html ].. Experience
[ http://www.flickr.com/photos/fields ] ... Photos
[ http://www.aquicki.com/wiki ].............Wiki
[ http://del.icio.us/fields ] ............. Links
C143acf82f94860ef6e2cba52b2de831?d=identicon&s=25 Greg MacGregor (Guest)
on 2006-02-24 06: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])
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 White <craigwhite@azapple.com> wrote:
> >
> >
> > actions, how do I go about creating the CRUD interface that reacts to
>
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>



--
Greg MacGregor
Web Developer
416-516-0395
www.sixminutes.ca
C1e5a9e9344b6d31b9df7303e6dc378a?d=identicon&s=25 Craig White (Guest)
on 2006-02-24 06:03
(Received via mailing list)
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
This topic is locked and can not be replied to.