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

  • Home
  • SEARCH
  • 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 784303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:41:28+00:00 2026-05-14T20:41:28+00:00

obj.update_attribute(:only_one_field, ‘Some Value’) obj.update_attributes(field1: ‘value’, field2: ‘value2’, field3: ‘value3’) Both of these will update

  • 0
obj.update_attribute(:only_one_field, 'Some Value')
obj.update_attributes(field1: 'value', field2: 'value2', field3: 'value3')

Both of these will update an object without having to explicitly tell ActiveRecord to update.

Rails API says:

update_attribute

Updates a single attribute and saves the record without going through the normal validation procedure. This is especially useful for boolean flags on existing records. The regular update_attribute method in Base is replaced with this when the validations module is mixed in, which it is by default.

update_attributes

Updates all the attributes from the passed-in Hash and saves the record. If the object is invalid, the saving will fail and false will be returned.

So if I don’t want to have the object validated I should use #update_attribute. What if I have this update on a #before_save, will it stackoverflow?

My question is does #update_attribute also bypass the before save or just the validation.

Also, what is the correct syntax to pass a hash to #update_attributes … check out my example at the top.

  • 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-14T20:41:29+00:00Added an answer on May 14, 2026 at 8:41 pm

    Please refer to update_attribute. On clicking show source you will get following code

          # File vendor/rails/activerecord/lib/active_record/base.rb, line 2614
    2614:       def update_attribute(name, value)
    2615:         send(name.to_s + '=', value)
    2616:         save(false)
    2617:       end
    

    and now refer update_attributes and look at its code you get

          # File vendor/rails/activerecord/lib/active_record/base.rb, line 2621
    2621:       def update_attributes(attributes)
    2622:         self.attributes = attributes
    2623:         save
    2624:       end
    

    the difference between two is update_attribute uses save(false) whereas update_attributes uses save or you can say save(true).

    Sorry for the long description but what I want to say is important. save(perform_validation = true), if perform_validation is false it bypasses (skips will be the proper word) all the validations associated with save.

    For second question

    Also, what is the correct syntax to pass a hash to update_attributes… check out my example at the top.

    Your example is correct.

    Object.update_attributes(:field1 => "value", :field2 => "value2", :field3 => "value3")
    

    or

    Object.update_attributes :field1 => "value", :field2 => "value2", :field3 => "value3"
    

    or if you get all fields data & name in a hash say params[:user] here use just

    Object.update_attributes(params[:user])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.