I am working in Rails 2.3.x on a learning management system. Here’s my code:
-@users.each do |user|
%tr
%td
=link_to h(user.name), :action => :show_user, :id => user.id
%td="#{h user.grade_level}"
-if QuizResult.find_by_user_id(@user_id).present?
="#{(QuizResult.average('score', :conditions => 'user_id = #{@user.id}') * 100).round}%"
-else
%em No quizzes taken
My quiz_results table has columns for user_id and score, among others. I have a record with a user_id (3907) and result (0.1), and two users I’m looking at with no records in the quiz_results table.
The display says "No quizzes taken" for all three, which leads me to believe that this line is false no matter what:
-if QuizResult.find_by_user_id(@user_id).present?
Any ideas how to fix?
Change
@user_idtouser.idin theifstatement and@user.idtouser.id. Also change the single quotations to double quotations or using string interpolation won’t work.