Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8456191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:29:01+00:00 2026-06-10T12:29:01+00:00

Working on a learning management system. NOT a RoR person. Have the line of

  • 0

Working on a learning management system. NOT a RoR person. Have the line of HAML to generate an average score based on quizzes taken:

="#{(QuizResult.average('score', :conditions => "user_id = #{@user.id}") * 100).round}%"

The quiz_results table has columns for used_id and score.

However, if there are no records in the quiz_results table, the page doesn’t render. I want to check if any scores exist for that user id, and if so, to show the average. If none exist, I want to display “No quizzes taken.” here’s what I have:

19:             %td
20:                 -if QuizResult('score', :conditions => "user_id = #{@user.id}").exists?
21:                     ="#{(QuizResult.average('score', :conditions => "user_id = #{@user.id}") * 100).round}%"
22:                 -else
23:                     %em No quizzes taken

I get the following error:

“ActionView::TemplateError (undefined method `QuizResult’ for #ActionView::Base:0x7028c7f5cb88>) on line #20 of app/views/manage_users/show_all_users.haml:”

I’ve been struggling all day with this. Any suggestions? Thanks in advance, from an RoR noob.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T12:29:02+00:00Added an answer on June 10, 2026 at 12:29 pm

    I am guessing that QuizResult is a model class. If that is the case then you cannot use it as a method to look up an instance.

    There are various ways that you can look up an object by some condition, for example:

    - if QuizResult.find_by_user_id(@user_id).present?
    

    To check for null (or nil as its referred to in Ruby) you can use the nil? method that Ruby itself provides or the Rails convenience method present? which returns true unless the object is nil, an empty string or empty collection.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working with a Learning Management system called Ilias ( http://www.ilias.de/ ). I
I am working in Rails 2.3.x on a learning management system. Here's my code:
I have been working on learning the Android NDK the past few days, but
I'm working on learning Objective-C/Coaoa, but I've seem to have gotten a bit stuck
I'm working on learning GWT (total newb) and have a question regarding the Visualiztion
I have been working on learning ANTLR in order to create a domain specific
I have been working on learning C++ and Qt4 recently, but I have hit
I am working on learning Android. From the documents I have read so far
I'm new to C# and have been working on learning database's. Currently I'm trying
I'm working on learning TDD while writing some small ruby programs. I have the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.