I’m running a loop (illustrated below) that retrieves records from a
table based on an id that might be different with each iteration. The
loop uses the array scrns (composed of IDs) to find the related records
in the Screens table. I’m attempting to store the returned results in
an instance variable so I can use that data in a view. However, this
code simply is overwriting the instance variable with each iteration.
Why? I want to end up with an array or hash in the instance var so I
can iterate through it in my view to display.
for scr in scrns
@scrs = Screen.find(:all, :conditions => [ “id = ?”, scr.screen_id ])
I’ve tried modifying the statement above in multiple ways:
@scrs << Screen.find( blah blah
@scrs += Screen.find( blah blah
Screen.find( blah blah).collect blah
Nothing is working. Any ideas?