December 16th, 2006, 03:36 PM
Help w/ pulling data from 2 tables and displaying the results
I'm brand new to ruby and I'm having trouble pulling data from one
table (table_1), looping through the results and pulling data from
another table (table_2) and displaying the results of table_2 in one
the pseudo code would be as follows:
The display would look like this for 1 row:
result_1 = select first_name from table_1
puts "<tr><td> results_1.first_name<td>"
results_2 = select table_2.info from table_2 where table_1.user_id = table_2.user_id;
joe | -info 1
Help - I'm desparate!
clem_c_rock is online now Report Post Edit/Delete Message
Last edited by CLEM_C_ROCK; December 17th, 2006 at 04:13 PM.
December 17th, 2006, 02:39 PM
Umm, you could revise your select statement to this:
This way, you need only one loop and the data is in the tabular format you need.
select table1.first_name, table_2.info from table_2 where table_1.user_id = table_2.user_id;
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne
"I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
December 19th, 2006, 12:59 PM
Ok - I finally buckled down and asked a couple of questions and there
was a method in the accounts model that was killing this whole concept:
The project I'm building a little addition to is huge and extremely complex so there's a lot of code that could overide or clash w/ code I'm trying to develop.
That was the case here. In the Account model there was this method that was overiding my join attempts.
spaces = Space.find :all, :conditions => ['owner_id = ?',
Now, once I got rid of that method - this works perfectly!
@accounts = Account.find(:all, :include => :spaces, :limit => 20)
I got dumped right into the fire w/ this new project - it pays to ask a few simple questions. I tore a lot of hair out trying to figure it out, but also learned a great deal trying to find the answer.