I’m looking for a way to share one ActiveRecordStore session between
multiple apps. I’m sure its possible, but not sure how. Ideas?
I guess this would hinge on setting a domain level cookie,
as its the cookie which hooks in the session id.
You could then connect to a shared database for your session store
in databases.yml you’d have to define
sessions_development:
host: blah
name: blah
sessions_test:
blah
…
class ActiveRecordStore::Session
establish_connection(“sessions#{RAILS_ENV}”.intern)
end
and probably
class ActiveRecordStore::SqlBypass.connection =
ActiveRecordStore::Session.connection
haven’t tried it,
but it makes sense,
I think.
Jarod R. wrote:
I’m looking for a way to share one ActiveRecordStore session between
multiple apps. I’m sure its possible, but not sure how. Ideas?
On Jul 18, 2007, at 08:45 , Jarod R. wrote:
I’m looking for a way to share one ActiveRecordStore session between
multiple apps. I’m sure its possible, but not sure how. Ideas?
Memcache.
If you use Memcache to store your sessions, then you can easily
access data across your applications. You just need to make sure you
don’t have namespace collisions or your data will get mixed up
between the sites.
I know, not a very traditional solution to this problem, but for
sites running on more than one server Memcache should be used anyway
IMHO so you get the added benefit for free.
– Mitch
and of course,
you get into a whole annoying world if your running your tests off
multiple dbs.
(you may just want to keep the same database for dev and test)
On Jul 18, 2007, at 6:46 AM, Jarod R. wrote:
Thanks Mitch. Memcache would probably work however at the moment it
isn’t in the cards. The apps use the same database to store sessions.
The question is how to make the session persist across apps.
Short answer, you can’t Longer answer: It’s easy enough to share
the database sessions table but the cookies that store the session_id
are tied to the domain they we’re served from. So the only way to
share the sessons out of the box is to use subdomains and set the
session cookie correctly.
set the sessions cookie domain to .example.com the . is important
Then you can use the same sessions cookies across subdomains like
foo.example.com bar.example.com
Cheers-
– Ezra Z.
– Founder & Ruby Hacker
– [email protected]
– Engine Y., Serious Rails Hosting
– (866) 518-YARD (9273)
Ezra Z. wrote:
the database sessions table but the cookies that store the session_id
Cheers-
Ezra, thats more along the lines of what I thought it would be. And it
works well enough for my needs. Out of curiosity, though, could one
persist the actual object using DRB?
– Jarod
Mitch P. wrote:
access data across your applications. You just need to make sure you
Thanks Mitch. Memcache would probably work however at the moment it
isn’t in the cards. The apps use the same database to store sessions.
The question is how to make the session persist across apps.
The real answer to your question depends on what exactly you are
trying to accomplish. Sharing sessions might be the best, or even a
good solution. For example if your apps all require a login, just
create a separate table to hold the information you want to share and
key it off the username. Memcache would be perfect for this, not sure
why you are ruling it out.
If your apps all require a login, and the shared data absolutely has
to be saved on every request, then you can share sessions by creating
a username column in the sessions table, and modify activerecord so
when someone logs in it checks to see if a session exists for the
user, and if so resets the cookie session id to that user. That way
lies madness, but it can work in the right circumstances.
Chris