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…
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.
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.
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 }
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.
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.