# Rows Affected

**URL:** <https://www.ruby-forum.com/t/rows-affected/173179>\
**Category:** Rails\
**Created:** [August 4, 2009, 3:18pm UTC](https://www.ruby-forum.com/t/rows-affected/173179 "2009-08-04T15:18:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [August 4, 2009, 3:18pm UTC](https://www.ruby-forum.com/t/rows-affected/173179/1 "2009-08-04T15:18:58Z")

</div>

Champs,

Actually the scenario is:-  
I am updating attributes for a record in a condition… And then i am  
flashing a message stating that record updated … But the thing is even  
if i dont update nething … i mean the if i’ll enter the same data as  
previous one then also giving me as updated …

So, Can neone let me know that how can i find the number of rows/columns  
affected after executing a query in rails …

Looking for u guyz …

Cheers …

---

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [August 5, 2009, 11:45am UTC](https://www.ruby-forum.com/t/rows-affected/173179/2 "2009-08-05T11:45:12Z")

</div>

The #changed method from the ActiveRecord::Dirty module should help  
with this, it gives you an array of all the attributes (a.k.a columns)  
you’ve changed on the model. To use it you have to update the  
attributes and save in two separate steps.

Something like this:

@user = User.find(params[:id])  
@user.attributes = params[:user]  
@user.changes # Get the array of what was changed here  
@user.save! # Then save the model after.

Take a look at the documentation for the methods provided in  
ActiveRecord::Dirty to find out more  
[http://api.rubyonrails.org/classes/ActiveRecord/Dirty.html](http://api.rubyonrails.org/classes/ActiveRecord/Dirty.html)

Cheers,  
Jeremy

On Aug 5, 1:18 am, Hemant B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
