The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

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

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.?

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.

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.