Forum: Ruby on Rails storing data from database into array

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
4b53f2d5af863c22c6d7e35caa66f84e?d=identicon&s=25 Neeraj Kapoor (nekapoor)
on 2007-06-25 18:32

I don't know what the Rails multidimensional array structure is and I am
having a problem in this regard.

Basically we have a set of games and in a XMLFEEDS table we have basic
information about the games (the game date, the sport type of the game).
Then in the PARTS table, we have two entries per xmlfeed entry which
correspond to the two teams participating in the game.

Essentially, right now I have a line in my code that goes like this:
@local_lines1 = Xmlfeed.find(:all, :conditions => ["id = ?", @id])

This is guaranteed to give me exactly one row from the database and as
such, am able to make a call like this:

@visiting_team = @local_lines1[0].parts[1].participant_name

where the xmlfeeds table and the parts table have been linked in a model
somewhere.   I am able to just reference the zeroth element of the
@local_lines1 variable since I know that there is only 1 row that is
being selected from the database call.

But now I want to store all of the data from the xmlfeed in a session
variable so I do this:

session[:lines] = Xmlfeed.find(:all);

But this now should be a multidimensional array of data since there are
multiple rows being selected.

My question is, how do I again get that row that corresponds to the @id
variable so that i can access all data corresponding to that row?

I have tried simply doing this:
@local_lines1 = session[:lines].select {|record| == @id}

which I think should give me the one row that I want, but then when I
try to access, for example, the visiting them the way I previously tried
(i.e. @local_lines1[0].parts[1].participant_name), my application fails.

I hope this wasn't too confusing!  If anyone has any ideas, I would
greatly appreciate it.

Thank you so very much ahead of time for your help.
This topic is locked and can not be replied to.