I just realized that since the objective is to modify another user's
session data (as opposed to my own), the code I am using will work.
There's one caveat, however, and someone correct me if I'm wrong: If
the user who's session data we are changing makes a request at the exact
same time as our user who is modifying data, there's a chance that he
will overwrite our changes, and there is no easy way to detect this. Or
is this not true in a single-threaded environment?
That being said, I'm also slightly embarrassed to post the following
code, I have a feeling there's a much better way to do this. But here
goes:
@@connection ||= ActiveRecord::Base.connection
record = @@connection.select_one("SELECT * FROM sessions WHERE
session_id = '#{other_sess_id}'")
a = record['data']
b = Marshal.load(ActiveSupport::Base64.decode64(a)) #demarshal and load
session into b
b[:testdata] = 'data here'
c = ActiveSupport::Base64.encode64(Marshal.dump(b)) #marshal
@@connection.update("UPDATE sessions SET data = '#{c}' WHERE session_id
= '#{other_sess_id}'") #save to db
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
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
-~----------~----~----~----~------~----~------~--~---