SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    May 2003
    Location
    virginia
    Posts
    988
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Rails application + sub applications + scaffold

    Hi,

    I'd like to create an admin suite, that contains sub applications. I want to be able to access my admin panel by going to '/admin' and be able to share the resources (models etc) within the related applications. Here is an example:

    Display main page:
    /admin/
    Would display total products, last five orders

    Products:
    /admin/products
    Display paging list etc.

    Product Edit:
    /admin/products/edit/1
    Form for editing products

    Orders:
    /admin/orders
    Display paging list etc.

    Edit Order:
    /admin/orders/edit/1

    Store:
    /store
    Listing of products

    Store Product:
    /store/product/3
    product details

    Home Page:
    /

    How do I go about doing that while still using the scaffold generator? Can I specifiy a directory for the controllers to go into? like:
    ./script/generator scaffold products admin/products

    - matt

  2. #2
    SitePoint Guru
    Join Date
    May 2003
    Location
    virginia
    Posts
    988
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Another issue:

    In my views folder I have generically named files like edit, new etc., but they'll be different for each action, obviously. How is this dealt with? Do I create actions like delete_product, new_product etc? instead of new, delete, edit etc.?

    -matt

  3. #3
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Code:
    ruby script/generate scaffold Admin::Product
    ruby script/generate scaffold Admin::Category
    This will create the namespace/directory structure you want. If you want to have the 5-product listing in /admin/, then I suggest editing routes.rb to point to a view/controller method from the Admin::Product controller (since it's really a product page).

    As for your second question, you can either accept the defaults and change the file names/controller methods afterwards, or you can run a command like so:
    Code:
    ruby script/generate controller Product delete_product new_product
    Which will make your Product controller with 2 methods, delete_product and new_product. Then you create the views to go with these methods yourself.

  4. #4
    SitePoint Guru
    Join Date
    May 2003
    Location
    virginia
    Posts
    988
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK cool. I did:
    ./script/generator scaffold --help
    and found out more about the script. I didn't use the :: but a / instead and it seemed to resolve.

    After I did the scaffold for admin/products, the browser/server wasn't finding it. I then created a new controller called admin with the index action. Still didn't work. So I restarted my computer. Then loaded the page. Then it found my admin index action. But still no admin/products. After I deleted the admin_controller I created, the admin/products page was finally working and now, everything is working great.

    Thanks for your help,

    matt


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
  •