SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    Awesome Addict
    Join Date
    Mar 2004
    Location
    Toronto, Canada
    Posts
    326
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Rails: regarding controllers

    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:
    Code:
    http://localhost:3000/admin/product/   #lists products
    http://localhost:3000/admin/product/edit/1
    http://localhost:3000/admin/category/new
    http://localhost:3000/admin/warehouse/show/16
    ... rather than just simply:

    Code:
    http://localhost:3000/admin/edit/1
    http://localhost:3000/admin/list
    http://localhost:3000/admin/show/16
    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 for each of them?

    Hope my explanation makes sense. Any help appreciated.

  2. #2
    SitePoint Guru silver trophy Luke Redpath's Avatar
    Join Date
    Mar 2003
    Location
    London
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gregor002
    In my first example, are product, category and warehouse controllers as well?
    Yes. Controllers should be aimed at a specific task. You should avoid god controller classes as much as any other god class.

    If you start seeing yourself with controller methods like create_xxx, edit_xxx, create_yyy, edit_yyy for example, its a sign you really need an XXX and YYY controlller.

    You can put controllers in modules, which will be located in app/controllers/modulename/ - in this case, an admin module.

    Code:
    > ./script/generate controller admin/products
    Creates app/controllers/admin/products_controller.rb

    Access it at http://myapp/admin/products

  3. #3
    Awesome Addict
    Join Date
    Mar 2004
    Location
    Toronto, Canada
    Posts
    326
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for that Luke. I've realized that modules are the route that I want to take.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •