Topic: Application Design - Navigation Routes

I am fairly new to rails, and have been through a few books, and am now starting to sketch out an application, however I have run into a problem with regards to the structure of the app.

I want to build an application that is setup in modules, and examples of urls could be:

/Sales <- frontpage for sales
/Sales/Customers <- customer index
/Sales/Invoices <- sales invoice index
/Sales/Invoice/123 <- show invoice 123
/Sales/Invoice/123/Post <- post action for the invoice
/Purchase <- frontpage for purchases
/Purchase/Vendors <- vendor index

So I would like to build the app with modules of sales, purchase, inventory etc. What is the best way of setting this up? Do I make a controller for each module or should I use namespaced routes for this or is there a better way?

Thanks in advance

Re: Application Design - Navigation Routes

Hi mickii,

I assume you are developing on Rails 3; Rails 2 routing is very different.

This article is a great resource:

Make sure you are familiar with use of RESTful routes.  One of the routes you propose go against the RESTful model (e.g. /Post) and although you could force Rails into doing it it's probably not the best path (although it's up to you of course)

The rest of your proposed routes will work fine in Rails - they are referred to as nested routes.

To start this off, I suggest you use the Scaffold generator that will also add flat routes into your routes.rb file.  You can see the generated routes by running:

rake routes

After all of the models, controllers, views and default routes are setup and functional, you can go into routes.rb and setup nested routes.

Here is an example:

resources :sales do
  resources :customers
  resources :invoices

resources :purchases do
  resources :vendors

I hope this helps.

Last edited by pglombardo (2011-05-31 12:59:31)

Re: Application Design - Navigation Routes

Thank you! That really put me on the right track. Ended up doing this, which does exactly what I want:

resource :sales, :only => [:show] do
  resources :customers