Wednesday, 30 May 2012

active record update_all class method

Hi,

Here is the method in Active Record that updates all records. You can update records based on condition also.


update_all(updates, conditions = nil, options = {})

ex:
1) Updating all user records with status to active

    User.update_all(:status => 'active')

    This will return the records count that were updated.


2)  Updating records based on condition
   
     User.update_all(:status => 'active', ['title like ?', 'uma'])





Thank You,
Uma Mahesh.


 

No comments:

Post a Comment