act_as_state_machine question

If I am in a form and I am editing it and I have a status of say
"being edited". If someone were to navigate away say to show all
forms or something is there a way to update the state of the form?

Me wrote:

If I am in a form and I am editing it and I have a status of say
"being edited". If someone were to navigate away say to show all
forms or something is there a way to update the state of the form?

That is generally not what a state machine is for. Your states should have a wider granularity, and users should push records into new states by explicitly submitting forms.

Even if you wrote an Ajax call in the "onblur" event of your form (if there is one), and even if the user's browser did not reject the call as an attempt to pop up an ad, your user might simply unplug from the grid suddenly.

To prevent users from editing the same record, do what Wikis do. Send out one form with a timestamp. When the POST comes back, compare the timestamp to the record's current stamp. If it has changed, inform the user they should use the Back button to retrieve their changes, they should copy them out to a Notepad, and then they should refresh their record to see the latest version.

OK, I have a status called "being_edited when a record is being updated. When this happens I removed the ability to edit the record from the SHOW screen. Ok so I guess if in the edit screeen do not have a navigation link?

Robert Walker wrote:

Phlip wrote:

To prevent users from editing the same record, do what Wikis do. Send
out one
form with a timestamp. When the POST comes back, compare the timestamp
to the
record's current stamp. If it has changed, inform the user they should
use the

Is there some reason to go through all this trouble with using
timestamps? Why not just use optimistic locking? I'm not saying this
isn't necessary, I'm actually curious of any advantage of using
timestamps.

Fail open instead of fail closed?

But I am more concerned about Chris's reply - I can't figure out the
question...

I just do this in my application.html page:

<% unless @mop.state.eql?(“Being_Edited”) %>
<%= link_to “New Mop”, :action => “new” %>
<%= link_to “Review Mop”, :action => “review” %>
<% end %>

Same thing really for the Show page, I just put an unless condition to
remove the “edit” link if the mop is being edited or looked at.

Chris Habgood wrote:

I just do this in my application.html page:

<% unless @mop.state.eql?("Being_Edited") %>
      <%= link_to "New Mop", :action => "new" %></h3></td>
      <%= link_to "Review Mop", :action => "review" %></h3></td>
<% end %>

Same thing really for the Show page, I just put an unless condition to
remove the "edit" link if the mop is being edited or looked at.

As a View style thing, a button should not just disappear if it wouldn't
have worked. Let the user click on the button, then provide a timely error
message.

How about you disable the link (make it grey, not <a>), and then put a
message next to it "Asok started editing this at 3:11"? Can someone think of
a way to do that, with a command override if Asok went home and left his
browser running?

Phlip wrote:

Chris Habgood wrote:

I just do this in my application.html page:

<% unless @mop.state.eql?("Being_Edited") %>
      <%= link_to "New Mop", :action => "new" %></h3></td>
      <%= link_to "Review Mop", :action => "review" %></h3></td>
<% end %>

Same thing really for the Show page, I just put an unless condition to
remove the "edit" link if the mop is being edited or looked at.

What prevents the user from typing the url by hand to edit the action? Then you'd have two users with the same form in the edit state. I don't think hiding the link is really preventative.

Cheers,
Darrik

Nothing really but the people who use this will most likely not know how to do that. Is there a better way to prevent someone from editing a form while someone else has it open? I saw something about optimistic locking but not quite sure what it really is or how to use it.