Gene Horodecki
2006-Nov-04 02:10 UTC
[Rails] Need help with iterating through a ''find'' result
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.
I have a main page in which I list all the Forums that a user is a member
of. I gather this data easily in my controller, with:
def list
@forums = Forum.find_by_user(@session[''user''].id)
end
However, I wish to extend this page and display the user''s status in
the
Forum on the corresponding line. The user''s status is in ForumMember.
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. 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. So
I''m
trying to do something like this:
def list
@forums = Forum.find_by_user(@session[''user''].id)
forummembers =
ForumMember.find_by_userid(@session[''user''].id)
forummembers.each {|fm| @forummember[fm.forumid] = fm}
@userid = @session[''user''].id
end
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. Can anyone tell me why the each
isn''t working
and how I can build my hash? Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060902/84821e42/attachment.html
