Hi, Im pretty new to Ruby as I''ve been programming for it for less than a month. I''m a php programmer that switched :) Anyways, I''m having an issue. I have my full site built in php and I''m using a legacy mysql database. I am building additions to my site with ruby on rails. However, my problem is that I need to be able to look at my live legacy database and grab a username and password from it. So all I need are two grab two variables from in there for user authentication, thats it. This has proved to be quite the challenge! The only solution I found is using something called DBI which I have to download and install on top of Ruby. This seems like overkill for such a simple query! Is there any way to do this simply with Ruby? It just seems ridiculous that there wouldnt be a way to do such a basic thing.. -- 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 -~----------~----~----~----~------~----~------~--~---
Where there is a will there is a way. There is a common misconception that Rails cannot connect to two databases, and this is not entirly true. You can connect rails to multiple databases(you can''t connect models to multiple database, well at least not easily). So in this case, you''d connect rails to your main DB(which I presume you already have) and then also connect it to the legacy database but you just have a User model that uses that second db connection. So anytime you do a User.find(:all) or maybe in your case User.find_by_sql(insert sql statement here) you will be interacting with your old db. Does that make any sense at all? Cheers, Cam Gab Gabi wrote:> Hi, > > Im pretty new to Ruby as I''ve been programming for it for less than a > month. I''m a php programmer that switched :) > > Anyways, I''m having an issue. I have my full site built in php and I''m > using a legacy mysql database. > > I am building additions to my site with ruby on rails. However, my > problem is that I need to be able to look at my live legacy database and > grab a username and password from it. So all I need are two grab two > variables from in there for user authentication, thats it. > > This has proved to be quite the challenge! The only solution I found is > using something called DBI which I have to download and install on top > of Ruby. This seems like overkill for such a simple query! > > Is there any way to do this simply with Ruby? It just seems ridiculous > that there wouldnt be a way to do such a basic thing.. > > -- > 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 Apr 19, 2007, at 6:47 PM, Gab Gabi wrote:> Im pretty new to Ruby as I''ve been programming for it for less than a > month. I''m a php programmer that switched :) > > Anyways, I''m having an issue. I have my full site built in php and I''m > using a legacy mysql database. > > I am building additions to my site with ruby on rails. However, my > problem is that I need to be able to look at my live legacy > database and > grab a username and password from it. So all I need are two grab two > variables from in there for user authentication, thats it.You can override a lot of the defaults from ActiveRecord in order to work with legacy databases, so that you can perform something like the above with ActiveRecord. class MyTable < ActiveRecord::Base set_primary_key "my_key_name" set_table_name "my_table_name" end See http://wiki.rubyonrails.com/rails/pages/HowToUseLegacySchemas for more examples. If your rails app and this model use entirely different databases. See the comments on this post for more on that (there may be a better reference but this is the best 2 minutes with google pulled up): http://blog.amber.org/2005/06/30/lost-in-multiple-rails/ James. -- James Stewart Play: http://james.anthropiccollective.org Work: http://jystewart.net/process/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Perfect! Worked! Thanks James :D -- 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 Apr 19, 4:15 pm, James Stewart <jystew...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: [...]> You can override a lot of the defaults from ActiveRecord in order to > work with legacy databases, so that you can perform something like > the above with ActiveRecord. > > class MyTable < ActiveRecord::Base > set_primary_key "my_key_name" > set_table_name "my_table_name" > end > > Seehttp://wiki.rubyonrails.com/rails/pages/HowToUseLegacySchemasfor > more examples.[...] Thank you for the link :) -Thufir --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---