Forum: Ruby on Rails multi user CRUD concurrency

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.
Dave R. (Guest)
on 2007-07-10 16:22
is there any tutorial/comments/blog about Rails multi-user concurrency
and how to prevent other users info from creeping into your session
if you both are accessing the same record...a rails newbie asks???
Daniel -. (Guest)
on 2007-07-10 16:50
(Received via mailing list)
On 7/10/07, Dave R. <removed_email_address@domain.invalid> wrote:
>
>
> is there any tutorial/comments/blog about Rails multi-user concurrency
> and how to prevent other users info from creeping into your session
> if you both are accessing the same record...a rails newbie asks???
>
> --


If your asking if another user modifies an active_record that you have
stored in a users session.  Don't do that.

The general consensus is don't store them there.  Rails sessions make no
attempt to keep in sync with the database, it just serializes the object
into the session, it doesn't hit the db again.  The way that a lot of
people
look after this is to store just the id into the session, then have a
lazy
loading method to get the record.

As an example, the restful_authentication plugin tracks the current user
with these two methods

    # Accesses the current user from the session.
    def current_user
      @current_user ||= (session[:user] &&
User.find_by_id(session[:user]))
|| :false
    end

    # Store the given user in the session.
    def current_user=(new_user)
      session[:user] = (new_user.nil? || new_user.is_a?(Symbol)) ? nil :
new_user.id
      @current_user = new_user
    end



There have been many blogs and threads on this list dealing with this
issue.  A quick google should turn up some answers.

HTH
Daniel
Dave R. (Guest)
on 2007-07-10 22:05
Daniel ----- wrote:
> On 7/10/07, Dave R. <removed_email_address@domain.invalid> wrote:
>>
>>
>> is there any tutorial/comments/blog about Rails multi-user concurrency
>> and how to prevent other users info from creeping into your session
>> if you both are accessing the same record...a rails newbie asks???
>>
>> --
>
>
> If your asking if another user modifies an active_record that you have
> stored in a users session.  Don't do that.
>
> The general consensus is don't store them there.  Rails sessions make no
> attempt to keep in sync with the database, it just serializes the object
> into the session, it doesn't hit the db again.  The way that a lot of
> people
> look after this is to store just the id into the session, then have a
> lazy
> loading method to get the record.
>
> As an example, the restful_authentication plugin tracks the current user
> with these two methods
>
>     # Accesses the current user from the session.
>     def current_user
>       @current_user ||= (session[:user] &&
> User.find_by_id(session[:user]))
> || :false
>     end
>
>     # Store the given user in the session.
>     def current_user=(new_user)
>       session[:user] = (new_user.nil? || new_user.is_a?(Symbol)) ? nil :
> new_user.id
>       @current_user = new_user
>     end
>
>
>
> There have been many blogs and threads on this list dealing with this
> issue.  A quick google should turn up some answers.
>
> HTH
> Daniel

...just using Rails simple defaults.... and storing things into a
database how does rails protect the database records ovriting newly
changed things that another user just changed...i'm going to re-write a
multi-user business process tracking system and want to know will my
data be safe from one user who makes changes to ID=100 at the same time
another user 100 miles away also to ID=100..does rails protect each user
from the other? i'll be using Oracle
Jack C. (Guest)
on 2007-07-10 22:33
(Received via mailing list)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1"
http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Dave R. wrote:
<blockquote cite="removed_email_address@domain.invalid"
 type="cite">
  <pre wrap="">Daniel ----- wrote:
  </pre>
  <blockquote type="cite">
    <pre wrap="">On 7/10/07, Dave R. <a class="moz-txt-link-rfc2396E"
href="mailto:removed_email_address@domain.invalid">&lt;removed_email_address@domain.invalid&gt;</a>
wrote:
    </pre>
    <blockquote type="cite">
      <pre wrap="">
is there any tutorial/comments/blog about Rails multi-user concurrency
and how to prevent other users info from creeping into your session
if you both are accessing the same record...a rails newbie asks???

--
      </pre>
    </blockquote>
    <pre wrap="">
If your asking if another user modifies an active_record that you have
stored in a users session.  Don't do that.

The general consensus is don't store them there.  Rails sessions make no
attempt to keep in sync with the database, it just serializes the object
into the session, it doesn't hit the db again.  The way that a lot of
people
look after this is to store just the id into the session, then have a
lazy
loading method to get the record.

As an example, the restful_authentication plugin tracks the current user
with these two methods

    # Accesses the current user from the session.
    def current_user
      @current_user ||= (session[:user] &amp;&amp;
User.find_by_id(session[:user]))
|| :false
    end

    # Store the given user in the session.
    def current_user=(new_user)
      session[:user] = (new_user.nil? || new_user.is_a?(Symbol)) ? nil :
new_user.id
      @current_user = new_user
    end



There have been many blogs and threads on this list dealing with this
issue.  A quick google should turn up some answers.

HTH
Daniel
    </pre>
  </blockquote>
  <pre wrap=""><!---->
...just using Rails simple defaults.... and storing things into a
database how does rails protect the database records ovriting newly
changed things that another user just changed...i'm going to re-write a
multi-user business process tracking system and want to know will my
data be safe from one user who makes changes to ID=100 at the same time
another user 100 miles away also to ID=100..does rails protect each user
from the other? i'll be using Oracle

  </pre>
</blockquote>
Check out optimistic locking.<br>
<br>
<pre class="moz-signature" cols="72">--
Jack C.
<a class="moz-txt-link-abbreviated"
href="mailto:removed_email_address@domain.invalid">removed_email_address@domain.invalid</a></pre>
<br>
--~--~---------~--~----~------------~-------~--~----~<br>
You received this message because you are subscribed to the Google
Groups &quot;Ruby on Rails: Talk&quot; group. <br> To post to this
group, send email to removed_email_address@domain.invalid <br> To
unsubscribe from this group, send email to
removed_email_address@domain.invalid <br> For more options,
visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en <br>
-~----------~----~----~----~------~----~------~--~---<br>
</body>
</html>
<br>
This topic is locked and can not be replied to.