Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8920293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:13:58+00:00 2026-06-15T06:13:58+00:00

Trying to get previous values from the object on save. Think of this scenario:

  • 0

Trying to get previous values from the object on save. Think of this scenario:

@object = {:name => 'Dan', :occupation => 'student'}
@object[:occupation] = 'Full time employee'
@object.value_was[:occupation] # => 'student'

I hope it is understandable enough that there is no method value_was. More over I would like to do the same on model objects:

@student = Student.find(1)
@student.occupation = 'Full time employee'
@student.save
@student.value_was(:occupation) # => 'student'

Any help will be appreciated.

That would be really helpful

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:13:59+00:00Added an answer on June 15, 2026 at 6:13 am

    ActiveModel includes support for “dirty field marking“, which preserves before and after states for changed fields.

    You can use @student.occupation_was to get the previous value of occupation, and @student.occupation_changed? to get whether the value has changed or not.

    This only works BEFORE the save, as saving resets the changed states of the values. However, you could capture this data in a before_save callback if you need to use it after a record has been saved. You can preserve all of the changes by duplicating #changed_attributes in a before_save, for example, then query on them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Not sure how to describe what I'm trying to get from this question, but
i am trying to get the complete parameter map from the request object and
I am using this plugin from Get Hifi in my code. I am trying
I'm trying get the visible portion of UIImage from an UIImageView . UIImageView takes
Trying to get this expression to work, can someone look at it and tell
This is a follow-up to my previous query . I have been trying some
This is a follow up to my previous AngularJS question . I am trying
I'm trying to get some code working that a previous developer has written. Yep,
I'm trying to get nearest places from a WordPress database using Haversine formula My
So i am trying get 2 div-containers which both should contain centered text (Both

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.