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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
kwerle-e+AXbWqSrlAAvxtiuMwx3w@public.gmane.org
2010-Feb-22 22:34 UTC
Re: Couldn''t find Order with ID=pending_orders
On Feb 22, 5:34 am, SachinJ <sachinmayurjo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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. http://guides.rubyonrails.org/routing.html 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 Werle I am looking for a new Rails job: http://www.CircleW.org/kurt/pages/resume -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Kurt, Robert, Thanks for the guidance, I will try it. Regards, Sachin On Feb 23, 3:34 am, "kwe...-e+AXbWqSrlAAvxtiuMwx3w@public.gmane.org" <kurt.we...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Feb 22, 5:34 am, SachinJ <sachinmayurjo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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. > > http://guides.rubyonrails.org/routing.html > 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 Werle > I am looking for a new Rails job:http://www.CircleW.org/kurt/pages/resume-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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:in `find_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:in `show'' 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 On Feb 23, 12:55 pm, SachinJ <sachinmayurjo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi Kurt, Robert, > Thanks for the guidance, I will try it. > > Regards, > Sachin > > On Feb 23, 3:34 am, "kwe...-e+AXbWqSrlAAvxtiuMwx3w@public.gmane.org" <kurt.we...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On Feb 22, 5:34 am, SachinJ <sachinmayurjo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I have a Controller named Orders which has apending_ordersmethod > > > 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. > > >http://guides.rubyonrails.org/routing.html > > 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 Werle > > I am looking for a new Rails job:http://www.CircleW.org/kurt/pages/resume-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> 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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Yes.. Steve, got it. Thanks a lot for the tips, it really helped Thanks to Steve, Kurt and Robert for the help. Best, Sachin On Feb 24, 8:18 am, Steve Rowley <srow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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 thepending_orders > action. Point being, you should get rid of the "map.resources :orders" > route altogether. > > Best, > Steve-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 On Feb 24, 7:38 am, SachinJ <sachinmayurjo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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:in `find_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:in `show'' > > Request > > Parameters: > > {"id"=>"pending_orders"} > ---- > > The routes: > > map.resources :orders > map.resources :orders, :collection => { :pending_orders=> :get } > > Controller: > > defpending_orders > @orders = Order.all(:joins => > [:product, :customer, :unit], :include => :delivery, :conditions > =>[ may have some conditions ]) > end > > Regards, > Sachin > > On Feb 23, 12:55 pm, SachinJ <sachinmayurjo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi Kurt, Robert, > > Thanks for the guidance, I will try it. > > > Regards, > > Sachin > > > On Feb 23, 3:34 am, "kwe...-e+AXbWqSrlAAvxtiuMwx3w@public.gmane.org" <kurt.we...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > On Feb 22, 5:34 am, SachinJ <sachinmayurjo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I have a Controller named Orders which has apending_ordersmethod > > > > 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. > > > >http://guides.rubyonrails.org/routing.html > > > 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 Werle > > > I am looking for a new Rails job:http://www.CircleW.org/kurt/pages/resume-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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-- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks Punit, Got it rolling... Thanks, Sachin On Mar 1, 12:04 am, Punit Rathore <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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 > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.