SwitchUp SwitchUp Ranked Best Coding Bootcamps 2025

Rails active record model set default order

Altcademy Team wrote on 7 February 2018

How do I set default order for rails model when I don't want to use .order when retrieving data?

You can do the following
class Book < ActiveRecord::Base default_scope order('created_at DESC') end

Trusted by

Students and instructors from world-class organizations

Join the upcoming Cohort #111

Enroll for March 2nd, 2026