This sounds like the dirty object feature of Rails 2.1 would work
great:
http://ryandaigle.com/articles/2008/3/31/what-s-new-in-edge-rails-dirty-objects

Maybe even try to utilize some callback methods so you can capture and
display the changes to the user:
http://railsforum.com/viewtopic.php?id=23001

On Nov 5, 10:38 pm, Franz <[EMAIL PROTECTED]> wrote:
> I want to accomplish the following. I have an object that can be
> edited.  However, it can occur that two people might edit the object
> at the same time.  Instead of locking the object down, I prefer to
> tell the user how their version differs from the last version that was
> committed.
>
> Kinda like:
>
> respond_to do |format|
>   @document = Document.find_by_id(1)
>   @document.attributes = params[:document]
>   @changes = @document.diff(Document.find_by_id(1))
>    format.html { render :action => "edit" }
> end
>
> The edit screen then renders the changes for the user to compare.  The
> user can then apply some changes or ignore the changes and save.
>
> This works fine for regular fields, but when the object has has_many
> assoctiations, then the following would occur.
>
> respond_to do |format|
>   @document = Document.find_by_id(1)
>   @document.attributes = params[:document]  # => this call would
> update the database for all has_many associations
>   @changes = @document.diff(Document.find_by_id(1))  #=> retrieving
> the previous object state from the database is not possible since the
> associations have changed
>    format.html { render :action => "edit" }
> end
>
> I also tried to compare the object to the attributes kinda like this;
>
> respond_to do |format|
>   @document = Document.find_by_id(1)
>   @changes = @document.diff(params[:document])
>    format.html { render :action => "edit" }
> end
>
> But then the user's changes aren't stored on the object and all
> updates are lost.
>
> Any help is appreciated.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to