# Compare changes

**URL:** <https://www.ruby-forum.com/t/compare-changes/162678>\
**Category:** Rails\
**Created:** [March 12, 2009, 6:13pm UTC](https://www.ruby-forum.com/t/compare-changes/162678 "2009-03-12T18:13:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![giga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@giga](https://www.ruby-forum.com/u/giga)\
**Post date:** [March 12, 2009, 6:13pm UTC](https://www.ruby-forum.com/t/compare-changes/162678/1 "2009-03-12T18:13:19Z")

</div>

How can I compare an entry?

@edit = Data.find(4)

After this, user update some data en press submit.

How can compare, is there any changes in new @edit and what is in  
database?  
Have user chnged any data or pressed just submit without changes?

---

<div class="post-metadata">

**Author:** ![giga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@giga](https://www.ruby-forum.com/u/giga)\
**Post date:** [March 12, 2009, 7:41pm UTC](https://www.ruby-forum.com/t/compare-changes/162678/2 "2009-03-12T19:41:32Z")

</div>

On 12 Mar., 18:13, Fresh M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> How can compare, is there any changes in new @edit and what is in  
> database?  
> Have user chnged any data or pressed just submit without changes?

Try this in the #update action. It’s untested:

@edited\_data = Data.new(params[:data])  
@original\_data = Data.find(params[:id])  
if @edited\_data == @original\_data

# The data is NOT changed…

else

# The data IS changed…

end

I don’t know if the == operator works in this case, but try it out and  
come back if you get problems. 🙂

–  
Cheers,  
David K.  
[http://twitter.com/rubyguy](http://twitter.com/rubyguy)
