Rows Affected


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 …

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! # Then save the model after.

Take a look at the documentation for the methods provided in
ActiveRecord::Dirty to find out more


On Aug 5, 1:18 am, Hemant B. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs