Forum: Ruby on Rails Compare changes.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ead43bcb0202410540a6a7cee5955d46?d=identicon&s=25 Fresh Mix (giga)
on 2009-03-12 18:13
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?
36ed63ef68c172f148c491418395d0b5?d=identicon&s=25 rubyguy@ymail.com (Guest)
on 2009-03-12 19:41
(Received via mailing list)
On 12 Mar., 18:13, Fresh Mix <rails-mailing-l...@andreas-s.net> 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 Knorr
http://twitter.com/rubyguy
This topic is locked and can not be replied to.