Skip to content

Latest commit

 

History

History
23 lines (17 loc) · 701 Bytes

read-only-models.md

File metadata and controls

23 lines (17 loc) · 701 Bytes

Read-Only Models

Are you in the midst of a big refactoring that is phasing out an ActiveRecord model? You may not be ready to wipe it from the project, but you don't want it accidentally used to create any database records. You essentially want your model to be read-only until it is time to actually delete it.

This can be achieved by adding a readonly? method to that model that always returns true.

def readonly?
  true
end

ActiveRecord's underlying persistence methods always check readonly? before creating or updating any records.

source

h/t Josh Davey