I am working on a site that has Forums.  There are two tables that track the users on this site.  One table 'Users' is basically the table for the salted_authentication generator.  The next table, 'ForumMember' tracks each user's status in each forum.  ForumMember contains a foreign key to Forum, and to User.
<br><br>I have a main page in which I list all the Forums that a user is a member of.&nbsp; I gather this data easily in my controller, with:<br><br>def list<br>&nbsp;&nbsp;&nbsp; @forums = Forum.find_by_user(@session['user'].id)<br>end<br><br>
<br>However, I wish to extend this page and display the user's status in the Forum on the corresponding line.&nbsp; The user's status is in ForumMember.&nbsp; I don't wish to do a SQL query for each forum on the list, so I want to prepare ahead of time by building a hash containing the corresponding ForumMember entries.&nbsp; I do this all the time in Perl.. I plan to index the hash to get the status as I iterate through the forums in the view.&nbsp; So I'm trying to do something like this:
<br><br>def list<br>&nbsp;&nbsp;&nbsp; @forums = Forum.find_by_user(@session['user'].id)<br>&nbsp;&nbsp;&nbsp; forummembers = ForumMember.find_by_userid(@session['user'].id)<br>&nbsp;&nbsp;&nbsp; forummembers.each {|fm| @forummember[fm.forumid] = fm}<br>&nbsp;&nbsp;&nbsp; @userid = @session['user'].id
<br>end<br><br>But ruby won't let me use the '.each'. I'm hoping you will be able to follow what I'm trying to do here.&nbsp; Can anyone tell me why the each isn't working and how I can build my hash?&nbsp; Thanks!<br><br>