Couldn't find Order with ID=pending_orders

I have a Controller named Orders which has a pending_orders method
which is expected to fetch some records from the database.

If i dont write a route for this method, I get the following error
when i call this method.

Couldn’t find Order with ID=pending_orders
I am using rails 2.3.5, in the previous versions i use to get this
I am not getting whether its new version requirement…

Help Appreciated.

Sachin

SachinJ wrote:

I have a Controller named Orders which has a pending_orders method
which is expected to fetch some records from the database.

If i dont write a route for this method, I get the following error
when i call this method.

Couldn’t find Order with ID=pending_orders
I am using rails 2.3.5, in the previous versions i use to get this
I am not getting whether its new version requirement…

It seem obvious you have a routing configuration problem, without more
detail it’s not easy to help you. What can be gleaned from this is that
the router is confusing the action to be called with the id parameter.

It’s difficult to say why, without seeing the related route(s), or at
least the URL giving you the problem.

Hi Kurt, Robert,
Thanks for the guidance, I will try it.

Regards,
Sachin

I tried putting the routes as you mentioned, still It doesn’t seems to
work, let me put some more details of this problem.

The error -

ActiveRecord::RecordNotFound in OrdersController#show

Couldn’t find Order with ID=pending_orders

F:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/
base.rb:1586:in find_one' F:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/ base.rb:1569:infind_from_ids’
F:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/
base.rb:616:in find' F:/rails_app/../.../app/controllers/orders_controller.rb:29:inshow’

Request

Parameters:

{“id”=>“pending_orders”}

The routes:

map.resources :orders
map.resources :orders, :collection => { :pending_orders => :get }

Controller:

def pending_orders
@orders = Order.all(:joins =>
[:product, :customer, :unit], :include => :delivery, :conditions
=>[ may have some conditions ])
end

Regards,
Sachin

The routes:

map.resources :orders
map.resources :orders, :collection => { :pending_orders => :get }

If you have both of these routes defined in routes.rb, it will still
fail because routes are processed in order (top-to-bottom) as the
appear in the file, so the routing logic would still match the first
route and produce the error; it would never attempt to match your
second route.

You could switch the order of those two lines, but the second route
will still match all of the other actions in your orders controller,
the only difference is that it will now also match the pending_orders
action. Point being, you should get rid of the “map.resources :orders”
route altogether.

Best,
Steve

On Feb 22, 5:34 am, SachinJ [email protected] wrote:

I have a Controller named Orders which has a pending_orders method
which is expected to fetch some records from the database.

If i dont write a route for this method, I get the following error
when i call this method.

Couldn’t find Order with ID=pending_orders
I am using rails 2.3.5, in the previous versions i use to get this
I am not getting whether its new version requirement…

So your route table has:
map.resources :orders

But you also want
/orders/pending_orders

rake routes shows:
order GET /orders/:id(.:format)
{:controller=>“orders”, :action=>“show”}

So when you are trying to do /orders/pending_orders, it is trying to
look up the id=‘pending_orders’.
Not what you want.

3.11.2 Adding Collection Routes

To add a collection route, use the :collection option:

map.resources :photos, :collection => { :search => :get }
This will enable Rails to recognize URLs such as /photos/search using
the GET HTTP verb, and route them to the search action of the Photos
controller. It will also create a search_photos route helper.

So you want:
map.resources :orders, :collection => { :pending_orders => :get }


Kurt W.
I am looking for a new Rails job:
http://www.CircleW.org/kurt/pages/resume

On the same thread i have another query, I have different types of
order listings for which I have a different query.
All the queries are separate methods thus have separate views which
renders the same list partial.

As experts suggested I create following routes.

map.resources :orders, :collection => { :inprocess_orders => :get }
map.resources :orders, :collection => { :unprocessed_orders
=> :get }
map.resources :orders

It worked fine for the inprocess_orders but the unprocessed_orders
again looks for a id with name ‘unprocessed_orders’

I am sure there is a minor correction i need to do, but not able to
make it working .
Any help appreciated.

Best,
Sachin

As mentioned in the previous post, the routes.rb file is processed
top-down.

So you need to change that line to

map.resources :orders, :collection => { :inprocess_orders => :get,
:unprocessed_orders> => :get }

Delete the other 2 lines i.e …
map.resources :orders, :collection => { :unprocessed_orders => :get
}
map.resources :orders

SachinJ wrote:

On the same thread i have another query, I have different types of
order listings for which I have a different query.
All the queries are separate methods thus have separate views which
renders the same list partial.

As experts suggested I create following routes.

map.resources :orders, :collection => { :inprocess_orders => :get }
map.resources :orders, :collection => { :unprocessed_orders
=> :get }
map.resources :orders

It worked fine for the inprocess_orders but the unprocessed_orders
again looks for a id with name ‘unprocessed_orders’

I am sure there is a minor correction i need to do, but not able to
make it working .
Any help appreciated.

Best,
Sachin

Yes… Steve, got it.
Thanks a lot for the tips, it really helped

Thanks to Steve, Kurt and Robert for the help.

Best,
Sachin

Thanks Punit,

Got it rolling…

Thanks,
Sachin