How to share user session to different top level domains belonging to the same rails app?

Hello, I am copying my question on
stackoverflowhttp://stackoverflow.com/questions/19975656/how-to-share-user-session-to-different-top-level-domains-belonging-to-the-same-rhere.

I have a single rails application running on one unicorn server,
where
a user can register and create a public profile. This profile is under a
subdomain that the user specifies and a top level domain based on the
country of the user. For example user_domain.appname.gr and
another_user_domain.appname.com.cy and so on.

The ‘appname’ part of the url does not change and the tld length based
on
country is not fixed. The base domain of the application is appname.gr.
Through that the user can access functionality like searching for public
profiles. He signs in under the appname.gr domain and devise is used
for
user authentication.

Problem: If he visits another_user_domain.appname.com.cy he will
appear
as non signed in. For *.appname.gr everything is ok.

How the user session gets shared across all domains of the application?
I
searched about it but it is not clear to me how to solve this. One thing
I
suspect is that the session must be stored in the database but what
happens
with the cookies? When a user visits *.appname.com.cy and he already has
a
session and a cookie for *.appname.gr, how I know who is the user to get
his session?

Are there any common practices or gems that solve this problem?

Thanks in advance!

Did you get any solution to this?