malcoauri
malcoauri

Reputation: 12189

How to get list of updating attributes in Rails?

There is the following code:

validates :password, length: { minimum: 6 }, if:  :some_method?

def some_method?

end

For my some_method? I need to get list of attributes which are being passed to update. How can I do it? Thanks.

Upvotes: 1

Views: 218

Answers (1)

Kombo
Kombo

Reputation: 2381

ActiveRecord::Dirty might be what you are looking for.

Before you save the update to the database, obj.changes returns a hash of all modified attributes with a key of the attribute name, and an array of [from, to] for the newly assigned (but not saved) value.

Upvotes: 3

Related Questions