Skip to content

Commit 505ad2b

Browse files
committed
active model dirty yourself
1 parent dc94812 commit 505ad2b

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

active_model_dirty.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Person
2+
3+
include ActiveModel::Dirty
4+
5+
define_attribute_methods :name
6+
7+
def name
8+
@name
9+
end
10+
11+
def name=(val)
12+
name_will_change! unless val == @name
13+
@name = val
14+
end
15+
16+
def save
17+
# do persistence work
18+
changes_applied
19+
end
20+
21+
def reload!
22+
# get the values from the persistence layer
23+
clear_changes_information
24+
end
25+
26+
def rollback!
27+
restore_attributes
28+
end
29+
end

0 commit comments

Comments
 (0)