update_attribute & update_attributes

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 

& now refer update_attributes and look it’s 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 use save(false) where as 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 before_* callbacksassosciated with save.


My note: 1) update_attribute use save(false)=save(perform_validation=false) means the attribute will be saved

2) update_attributes use save(true)=save(perform_validation=true) means that the attributes will not be saved if any of them is invalid. And if ANY of the attribute violates the validation, ALL the attributes intended to be updated will not be changed.

Hello world!

Welcome to WordPress.com. After you read this, you should delete and write your own post, with a new title above. Or hit Add New on the left (of the admin dashboard) to start a fresh post.

Here are some suggestions for your first post.

  1. You can find new ideas for what to blog about by reading the Daily Post.
  2. Add PressThis to your browser. It creates a new blog post for you about any interesting  page you read on the web.
  3. Make some changes to this page, and then hit preview on the right. You can always preview any post or edit it before you share it to the world.