I''m new to RoR so please excuse a simple question. I''ve finished the first part of the Depot Application from AWDwR. When I create a new product it goes to the bottom of the list. How do I get new products to sort to the top? Thanks in advance. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Hi DP777 wrote:> I''m new to RoR so please excuse a simple question. I''ve finished the > first part of the Depot Application from AWDwR. When I create a new > product it goes to the bottom of the list. How do I get new products to > sort to the top?Find the find() method in the relevant controller and add ":order => ''id DESC''" to the parameters. This will find return the products from the database with the most recent first. If your product list url is site.com/products/list, you should have a file called app/controllers/products_controller.rb with a method similar to this: def list @products = Product.find(:all) [..] end change this to: def list @products = Product.find(:all, :order => ''id DESC'') [..] end Your file and method names may differ but this should give you a rough idea. Cheers, Mark --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Thats all right, but if you use this book, you have following code in app\controllers\admin_controller.rb: ... def list @product_pages, @products = paginate :products, :per_page => 10 end ... if you want to sort products by id, you should rewrite this code us: def list @product_pages, @products = paginate :products, :per_page => 10, :order => ''id DESC'' end ... Try it, or may be you want sort by title or price? -- Best Regards, Sergey --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---