Hi, I''m trying to connect to a second database, but I can''t seem to get it working. When a new user gets created in the application, the user data gets writter to the application database into the users table like all normal applications. After the user gets created, the application needs to connect to a second database. The second database is the pureftpd database where ftp user data gets stored. The problem is, the pureftpd database has a table called users, and so does my application, so creating a new model "user" like I have read in all the sites that give a small tutorial on multiple database connections is out of the question. I also tryed using ruby-sequel to handle the second database connection, but that conflicts with ActiveRecord. I have never set u multiple connection in one application, so I have no idea on what doing next, and I was hoping someone could help me out on this one. Thank you in advance. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jun 1, 11:32 am, Michael Rigart <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi, > > I''m trying to connect to a second database, but I can''t seem to get it > working. > > When a new user gets created in the application, the user data gets > writter to the application database into the users table like all normal > applications. After the user gets created, the application needs to > connect to a second database. The second database is the pureftpd > database where ftp user data gets stored. > > The problem is, the pureftpd database has a table called users, and so > does my application, so creating a new model "user" like I have read in > all the sites that give a small tutorial on multiple database > connections is out of the question. >The following should work (but I haven''t tried it , so it might not). Create a second class called PureFtpUser (or something like that). In that model, use set_table_name to set the table used to users and use establish_connection to tell it to connect to another database. If you don''t want to pollute your code with the connection details, ActiveRecord::Base.configurations contains all the configurations defined in your database.yml, so you can do something like establish_connection(ActiveRecord::Base.configurations["pureftp"] Fred> I also tryed using ruby-sequel to handle the second database connection, > but that conflicts with ActiveRecord. > > I have never set u multiple connection in one application, so I have no > idea on what doing next, and I was hoping someone could help me out on > this one. > > Thank you in advance. > -- > Posted viahttp://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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thank you for your quick reply. Everything seems to work as you described, except for the configurations[] part. When I specify the whole string, it works. But that is something I''ll check out later. Thank you again for the big help -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---