Forum: Ruby on Rails act_as_state_machine question

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.
Chris H. (Guest)
on 2009-04-18 03:57
(Received via mailing list)
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?
Phlip (Guest)
on 2009-04-18 04:29
(Received via mailing list)
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.

--
   Phlip
   http://flea.sourceforge.net/resume.html
Chris H. (Guest)
on 2009-04-18 04:39
(Received via mailing list)
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 W. (Guest)
on 2009-04-18 04:44
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.
Phlip (Guest)
on 2009-04-18 04:56
(Received via mailing list)
Robert W. 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...
Chris H. (Guest)
on 2009-04-18 05:34
(Received via mailing list)
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.
Phlip (Guest)
on 2009-04-18 06:21
(Received via mailing list)
Chris H. 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?
Darrik Mazey (Guest)
on 2009-04-18 07:55
(Received via mailing list)
Phlip wrote:
>> 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

--
Darrik Mazey
DMT Programming, LLC.
P.O. Box 91
Torrington, CT 06790
office: 330.983.9941
    fax: 330.983.9942
mobile: 330.808.2025
removed_email_address@domain.invalid

To obtain my public key, send an email to
removed_email_address@domain.invalid.
Chris H. (Guest)
on 2009-04-18 08:36
(Received via mailing list)
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.
This topic is locked and can not be replied to.