To clarify: Some of the data for my rails app is stored in a non-rails DB table. I need to query this other database and then show the data in the rails app.
I have a model (have tried with abstract class and without) Computers that is connected to the non-rails DB with establish_connection. Then in my controller I want to find all the computers in the non- rails DB and in my view I want to loop through the computers and show their name. I am trying to figure out the best way to query and show the data in the view. If I do row = Computer.connection.execute(query) I can then loop through the MySQL::Result list and access the data as an array - so row[0] gives me computer.name The problem with this is that I then need to know the position of the data in the result. I am wondering if there is a better way to query and then show the data. On May 19, 11:21 am, Rick DeNatale <[email protected]> wrote: > On Wed, May 19, 2010 at 1:50 PM, Kim <[email protected]> wrote: > > Well like I said, I am trying to figure out how to use an abstract > > class to access a separate database. I understand why calling the > > object attribute is not working, what I am looking for is the proper > > way to interact with the separate database. If an abstract class is > > not the way, what is? If not find_by_sql then is connection.execute > > the right way? Looking for an actual solution. > > I think you've got two things mixed up here. > > 1) the establish connection is what causes a model to connect to a > specific database, effectively overriding the standard connection > setup in ActiveRecord::Base. > > 2) If you want to have multiple models/tables connected to the same > database, the way to do that is to have an abstract class from which > they inherit the connection (much like normal models inherit the > connection from ActiveRecord::Base). > > So if you only have a single model/table in the database, then just > use 1 and not 2, I think. > > HTH > > -- > Rick DeNatale > > Blog:http://talklikeaduck.denhaven2.com/ > Github:http://github.com/rubyredrick > Twitter: @RickDeNatale > WWR:http://www.workingwithrails.com/person/9021-rick-denatale > LinkedIn:http://www.linkedin.com/in/rickdenatale > > -- > 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 [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group > athttp://groups.google.com/group/rubyonrails-talk?hl=en. -- 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

