Hi, I have two apps which are independent but I now would like to help them talk to each other. Specifically I would like to allow users registering to one site to be able to have an account created at the other automatically. Both sites use Restful_authentication plugin so the User table is the same structure, so all I would need to pass is name, email and password in some sort of information push. As you can tell from my terminology this is something I have no experience with so can anybody point me in the direction of a good tutorial, or have you tried something similar? Thanks, Dan -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Sun, Mar 7, 2010 at 7:35 AM, DanC <d.m.colegate-VlwAjOFxKoqFxr2TtlUqVg@public.gmane.org> wrote:> I have two apps which are independent but I now would like to help > them talk to each other. Specifically I would like to allow users > registering to one site to be able to have an account created at the > other automatically. > > Both sites use Restful_authentication plugin so the User table is the > same structure, so all I would need to pass is name, email and > password in some sort of information push.You can open a connection to the other DB and save the User there; see the ActiveRecord::Base API doc. That''s probably easier and better than messing with replication. But you''ll also want to consider other actions besides new (e.g. when the user updates their account data -- new email, change password, etc.) FWIW, -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hey Hassan,
Thanks for the pointer, I have been looking at the API and the
establish_connection seems like the way to go.
ActiveRecord::Base.establish_connection(
:adapter => "mysql",
:host => "localhost",
:username => "myuser",
:password => "mypass",
:database => "somedatabase"
)
The databases both exist on the same server but one is mysql and one
is postgresql.
It is not clear to me how to implement this though?
I suppose I could try adding it in the User model as a before_create
method and pass the params to the other database, but I have no idea
what kind of structure that would have.
Any further input would be very much appreciated, but I will keep this
thread updated if I manage to figure it out.
Best,
Dan
On 7 Mar, 17:09, Hassan Schroeder
<hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> On Sun, Mar 7, 2010 at 7:35 AM, DanC
<d.m.coleg...-VlwAjOFxKoqFxr2TtlUqVg@public.gmane.org> wrote:
> > I have two apps which are independent but I now would like to help
> > them talk to each other. Specifically I would like to allow users
> > registering to one site to be able to have an account created at the
> > other automatically.
>
> > Both sites use Restful_authentication plugin so the User table is the
> > same structure, so all I would need to pass is name, email and
> > password in some sort of information push.
>
> You can open a connection to the other DB and save the User there;
> see the ActiveRecord::Base API doc.
>
> That''s probably easier and better than messing with replication.
But
> you''ll also want to consider other actions besides new (e.g. when
the
> user updates their account data -- new email, change password, etc.)
>
> FWIW,
> --
> Hassan Schroeder ------------------------
hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
> twitter: @hassan
--
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
On Sun, Mar 7, 2010 at 12:29 PM, DanC <d.m.colegate-VlwAjOFxKoqFxr2TtlUqVg@public.gmane.org> wrote:> The databases both exist on the same server but one is mysql and one > is postgresql. > > It is not clear to me how to implement this though?I''m sure there''s more than one way, but here''s a suggestion. You have a User now class User < ActiveRecord::Base # whatever end Create a class AssociatedUser < User establish_connection :associated_site end Define associated_site in your database.yml Then you can simply "clone" your user a_user = AssociatedUser.new a_user.attributes= user.attributes a_user.save And done :-) Caveat: if this is an existing user (already saved in the first app) then you probably want to replace the above with something like a_user.attributes= user.attributes.except("id") to avoid clobbering someone else''s account. Serving suggestion, write lots of tests before implementing :-) -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.