Rails activerecord get Model. all using an order by

By default, when you do Model.all in rails, it returns data based on whatever order was returns by the database. But sometimes thats not what you want.

For example, if I had a model called ‘Product’ and wanted to retrieve all the products by order_date, here’s what you need to write in your controller.

Product.order('order_date DESC');

Ryan Sukale

Ryan is just a regular guy next door trying to manage his life and finances.

You may also like...