views:

22

answers:

1

To illustrate:

class Customer
  has_many :sales_orders
end

class SalesOrder
  belongs_to :customer
end

i want to have customer to list sales_order which is ready to be sent, should i:

  1. put the routing http://.../sales_orders/can_be_delivered or
  2. create a new controller for reporting http://.../reports/sales_orders_can_be_delivered

for the 1st one, what should goes in the route.rb?

for the 2nd one, nothing goes in route.rb, we can use the last defined route which is :controller/:action.. <-- but this isn't named route

any ideas for this kind of problem?

+1  A: 

I would go with the first option as the view you want is just another view on sales orders for which you already have a resource/controller.

The routes would be:

map.resources :sales_orders, :collection => {:can_be_delivered => :get}

This will give you .../sales_orders/can_be_delivered and the helpers can_be_delivered_sales_orders_path + can_be_delivered_sales_orders_url

Side notes

Along with the option :collection you could also add :only => [:new, :create, :destroy] if for example your controller only needed new, create and destroy from the standard restful actions.

ps. Make sure you put this above catch all route at the bottom which I would recommend you commenting out if all your actions are restful.

Finally this guide is a great start for routing in rails:

http://guides.rubyonrails.org/routing.html

tsdbrown
thank you. I'll try to go with your suggestions. thank you.
Hadi
No problem, good luck!
tsdbrown