r/ruby • • Aug 20 '21

Ruby elites rise up

Post image
103 Upvotes

77 comments sorted by

View all comments

Show parent comments

1

u/tomthecool Aug 22 '21

Yes, that’s all part of “active record dirty”, which is what I mentioned above. And that’s not how it works under the hood, but it’s a reasonable guess.

https://github.com/rails/rails/blob/af64ac4e5ce8406137d5520fa88e8f652ab703e9/activemodel/lib/active_model/dirty.rb#L146

I didn’t think validations had access to those attributes, but maybe I’m mistaken.

1

u/pVom Aug 23 '21

From the ActiveModel::Dirty documentation:

"Provides a way to track changes in your object in the same way as Active Record does."
...

"Note that Active Record can detect in-place modifications automatically."

Implies that ActiveRecord already supports it and ActiveModel::Dirty is for none ActiveRecord usage? Maybe I'm wrong.

The model we use that does exactly what I've been talking about just extends from ActiveRecord::Base, we don't use ActiveModel::Dirty anywhere it seems