Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add *_previously_was attribute methods when dirty tracking #36836

Merged
merged 2 commits into from Aug 1, 2019

Conversation

@dhh
Copy link
Member

@dhh dhh commented Aug 1, 2019

Add *_previously_was attribute methods when dirty tracking. Example:

pirate.update(catchphrase: "Ahoy!")
pirate.previous_changes["catchphrase"] # => ["Thar She Blows!", "Ahoy!"]
pirate.catchphrase_previously_was # => "Thar She Blows!"
@dhh dhh merged commit a0bb19f into master Aug 1, 2019
2 checks passed
Loading
@dhh dhh deleted the attribute_previously_was branch Aug 1, 2019
@OlgaCoskun
Copy link

@OlgaCoskun OlgaCoskun commented Oct 7, 2019

intresting!)

Loading

@mikker
Copy link
Contributor

@mikker mikker commented Oct 7, 2019

Just curious, feel free to ignore, @dhh: How do you use this in Basecamp (or that secret thing)? Like, use this in a sentence in the Dictionary 😊

Loading

@kaspth
Copy link
Member

@kaspth kaspth commented Oct 7, 2019

@mikker something like report_default_collections if collectable_id_previously_was.blank? is one, saved_change_to_status? && status_previously_was.inquiry.trashed? && active? is another. All in after_* callbacks, of course. 😊

Loading

@mikker
Copy link
Contributor

@mikker mikker commented Oct 7, 2019

Thanks Kasper! 🙏

Loading

@maxp-hover
Copy link

@maxp-hover maxp-hover commented Sep 9, 2021

Um, so I know it's kinda late to bring this up, but why didn't we use previous_value?

attr_previously_was.blank? sounds natural, but old_attr = thing.attr_previously_was just doesn't read like proper grammar, I expect an adjective after that. Meanwhile previous_value works in both cases.

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants