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 1028693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:25:47+00:00 2026-05-16T12:25:47+00:00

In my Rails application I’m trying to update a model’s attribute using update_attribute in

  • 0

In my Rails application I’m trying to update a model’s attribute using update_attribute in an after_create callback. I can successfully update the attribute, but for some reason all the model’s other attributes are also updated when I do so. So, even though the model’s name attribute (for example) has not changed it is set (to it’s current value) in the database update query.

Is this the expected behaviour in Rails (2.3.8), or am I doing something wrong?

  • 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-05-16T12:25:47+00:00Added an answer on May 16, 2026 at 12:25 pm

    Yes I believe this is consistent behaviour because that instance of your model that was just created has not been reloaded. Therefore the ‘changed’ attributes have not been reset.

    Sorry if that’s not a very clear explanation. To demonstrate, run the debugger in your after_create method. E.g.

    def my_after_save_callback
      require 'ruby-debug'; debugger
      update_attribute(:foo, "bar")
    end
    

    Then when the debugger starts run:

    p self.changed
    

    An array of all the attributes that have been modified for this object will be returned. ActiveRecord will update all these attributes the next time the object is saved.

    One way around this is to reload the object before updating the attribute.

    def my_after_save_callback
      reload
      update_attribute(:foo, "bar")
    end
    

    This will reset the ‘changed’ attributes and only the specific attribute you modify will be updated in the SQL query.

    Hope that makes sense 🙂

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

Sidebar

Ask A Question

Stats

  • Questions 510k
  • Answers 510k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Most likely your DB has run out of connections. That's… May 16, 2026 at 5:00 pm
  • Editorial Team
    Editorial Team added an answer I have used the latest version of the soaplib which… May 16, 2026 at 5:00 pm
  • Editorial Team
    Editorial Team added an answer Your main problem is some small changes in the jsonReader.… May 16, 2026 at 5:00 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

A Rails application with a RESTful interface needs to accept POST data using a
My Rails application makes use of Time.zone so that each user can set their
My Rails application have a User model and a Group model, where User belongs
My application is a set of two rails applications. Based on some parameters in
In my Rails application I'm trying to make the controllers skinnier and am having
My Rails application is running on a VM. The VM's performance is just fine
My Rails application has a number of tasks which are offloaded into background processes,
My rails application runs on a Ubuntu server machine. I need to create temporary
In rails application I have two models: Food and Drink . Both food and
I have a rails application where each user has a separate database. (taking Joel

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.