File tree 2 files changed +25
-1
lines changed
2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ variety of languages and technologies. These are things that don't really
7
7
warrant a full blog post. These are mostly things I learn by pairing with
8
8
smart people at [ Hashrocket] ( http://hashrocket.com/ ) .
9
9
10
- _ 431 TILs and counting..._
10
+ _ 432 TILs and counting..._
11
11
12
12
---
13
13
@@ -278,6 +278,7 @@ _431 TILs and counting..._
278
278
- [ Params Includes Submission Button Info] ( rails/params-includes-submission-button-info.md )
279
279
- [ Perform SQL Explain With ActiveRecord] ( rails/perform-sql-explain-with-activerecord.md )
280
280
- [ Pretend Generations] ( rails/pretend-generations.md )
281
+ - [ Read-Only Models] ( rails/read-only-models.md )
281
282
- [ Rescue From] ( rails/rescue-from.md )
282
283
- [ Retrieve An Object If It Exists] ( rails/retrieve-an-object-if-it-exists.md )
283
284
- [ Select A Select By Selector] ( rails/select-a-select-by-selector.md )
Original file line number Diff line number Diff line change
1
+ # Read-Only Models
2
+
3
+ Are you in the midst of a big refactoring that is phasing out an
4
+ ` ActiveRecord ` model? You may not be ready to wipe it from the project, but
5
+ you don't want it accidentally used to create any database records. You
6
+ essentially want your model to be read-only until it is time to actually
7
+ delete it.
8
+
9
+ This can be achieved by adding a ` readonly? ` method to that model that
10
+ always returns ` true ` .
11
+
12
+ ``` ruby
13
+ def readonly?
14
+ true
15
+ end
16
+ ```
17
+
18
+ ` ActiveRecord ` 's underlying persistence methods always check ` readonly? `
19
+ before creating or updating any records.
20
+
21
+ [ source] ( http://stackoverflow.com/questions/5641410/is-there-an-easy-way-to-make-a-rails-activerecord-model-read-only )
22
+
23
+ h/t Josh Davey
You can’t perform that action at this time.
0 commit comments